Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

policy Commands #379

Merged
merged 50 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
0a619bf
policy cut #1
Jan 24, 2019
f20d965
check #2
Jan 24, 2019
8a78a5e
build policy
Jan 24, 2019
dec8257
simply wow
Jan 24, 2019
3e39bf3
simply wow change
Jan 24, 2019
b7106ab
some minor cleanup
Jan 24, 2019
0d3552e
minor refactoring
Jan 24, 2019
597438b
added a UT for nameOfArray
Jan 24, 2019
016c0e6
added comment resolution policy
Jan 25, 2019
e0d7236
MergeStrategyPolicy done
Jan 25, 2019
35bf4cd
some refactoring here and there
Jan 25, 2019
9fb65da
work item linking policy
Jan 25, 2019
7dab3ce
some cleanup
Jan 25, 2019
07bee91
required reviewers
Jan 25, 2019
535e3c9
minor
Jan 25, 2019
df2d36d
minor refactoring for preparaion of update stuff
Jan 25, 2019
292a650
added update policy command
Jan 25, 2019
a8121b3
list policy UT
Jan 25, 2019
7009e09
minor
Jan 25, 2019
3b9d601
one more UT for get policy
Jan 25, 2019
e4bdbbc
added UT for delete policy
Jan 25, 2019
a4a1d19
some minor things
Jan 25, 2019
8b8abdb
test error message generation
Jan 25, 2019
b383a08
very small
Jan 25, 2019
bd277a1
create base test
Jan 25, 2019
ed7c0d3
UT for setting up scope
Jan 25, 2019
20ca49b
setting creation test
Jan 25, 2019
b618a4c
Id assignment in create policy
Jan 25, 2019
a726ae5
UTs done
Jan 25, 2019
c0fafa9
fix broken UT
Jan 25, 2019
7942fab
style fix in commands
Jan 25, 2019
c609c4e
try if line-too-long works
Jan 25, 2019
b7b6a5c
some style fixes
Jan 25, 2019
d7c53cd
some style fixes
Jan 25, 2019
06e0c69
more style fixes
Jan 25, 2019
d5758f0
remove the controversial code
Jan 25, 2019
18c7abf
fix some more styles
Jan 25, 2019
2f90ae8
flake 8 fixes
Jan 25, 2019
b358a67
final flake 8 fix
Jan 25, 2019
1be208b
added policy_configuration
Jan 29, 2019
47e2a95
fixing help texts
Jan 29, 2019
6457ac1
Merge branch 'master' of https://github.com/Microsoft/azure-devops-cl…
Jan 29, 2019
b6250b6
Pr comments
Jan 29, 2019
aa96f25
minor style fix
Jan 29, 2019
dc09dc8
fix UT to run without network
Jan 29, 2019
4c47911
try to stop pather
Jan 29, 2019
ac56450
Merge branch 'master' of https://github.com/Microsoft/azure-devops-cl…
Jan 29, 2019
0e3b850
make policy id mandatory in update command
Jan 29, 2019
f8fd265
handling negative scenario
Jan 29, 2019
a960e3f
style fix
Jan 29, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions azure-devops/azext_devops/dev/common/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,29 @@
DEVOPS_TEAM_PROJECT_DEFAULT = 'project'
PAT_ENV_VARIABLE_NAME = CLI_ENV_VARIABLE_PREFIX + 'PAT'
AUTH_TOKEN_ENV_VARIABLE_NAME = CLI_ENV_VARIABLE_PREFIX + 'AUTH_TOKEN'

# policy constants

APPROVER_COUNT_POLICY = 'ApproverCountPolicy'
APPROVER_COUNT_POLICY_ID = 'fa4e907d-c16b-4a4c-9dfa-4906e5d171dd'

BUILD_POLICY = 'BuildPolicy'
BUILD_POLICY_ID = '0609b952-1397-4640-95ec-e00a01b2c241'

COMMENT_REQUIREMENTS_POLICY = 'CommentRequirementsPolicy'
COMMENT_REQUIREMENTS_POLICY_ID = 'c6a1889d-b943-4856-b76f-9e46bb6b0df2'

MERGE_STRATEGY_POLICY = 'MergeStrategyPolicy'
MERGE_STRATEGY_POLICY_ID = 'fa4e907d-c16b-4a4c-9dfa-4916e5d171ab'

FILE_SIZE_POLICY = 'FileSizePolicy'
FILE_SIZE_POLICY_ID = '2e26e725-8201-4edd-8bf5-978563c34a80'

WORKITEM_LINKING_POLICY = 'WorkItemLinkingPolicy'
WORKITEM_LINKING_POLICY_ID = '40e92b44-2fe1-4dd6-b3d8-74a9c21d0c6e'

REQUIRED_REVIEWER_POLICY = 'RequiredReviewersPolicy'
REQUIRED_REVIEWER_POLICY_ID = 'fd2167ab-b0be-447a-8ec8-39368250530e'

REPO_POLICY_TYPE = [APPROVER_COUNT_POLICY, BUILD_POLICY, COMMENT_REQUIREMENTS_POLICY, MERGE_STRATEGY_POLICY,
FILE_SIZE_POLICY, WORKITEM_LINKING_POLICY, REQUIRED_REVIEWER_POLICY]
31 changes: 31 additions & 0 deletions azure-devops/azext_devops/dev/repos/_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,37 @@
_WORK_ITEM_TITLE_TRUNCATION_LENGTH = 70


def transform_repo_policies_table_output(result):
table_output = []
for item in result:
table_output.append(_transform_repo_policy_request_row(item))
return table_output


def transform_repo_policy_table_output(result):
table_output = [_transform_repo_policy_request_row(result)]
return table_output


def _transform_repo_policy_request_row(row):
table_row = OrderedDict()
table_row['ID'] = row['id']
table_row['Name'] = _get_policy_display_name(row)
table_row['Is Blocking'] = row['isBlocking']
table_row['Is Enabled'] = row['isEnabled']
# this will break if policy is applied across repo but that is not possible via UI at least now
table_row['Repository Id'] = row['settings']['scope'][0]['repositoryId']
table_row['Branch'] = row['settings']['scope'][0]['refName']
return table_row


def _get_policy_display_name(row):
gauravsaralMs marked this conversation as resolved.
Show resolved Hide resolved
if 'displayName' in row['settings']:
return row['settings']['displayName']

return row['type']['displayName']


def transform_pull_requests_table_output(result):
table_output = []
for item in result:
Expand Down
6 changes: 6 additions & 0 deletions azure-devops/azext_devops/dev/repos/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ def load_repos_help():
long-summary:
"""

helps['repos policies'] = """
type: group
short-summary: Manage Azure Repos branch policies.
long-summary:
"""

helps['repos pr'] = """
type: group
short-summary: Manage pull requests.
Expand Down
4 changes: 4 additions & 0 deletions azure-devops/azext_devops/dev/repos/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# --------------------------------------------------------------------------------------------

from knack.arguments import enum_choice_list
from azext_devops.dev.common.const import REPO_POLICY_TYPE

# CUSTOM CHOICE LISTS
_ON_OFF_SWITCH_VALUES = ['on', 'off']
Expand All @@ -18,6 +19,9 @@ def load_code_arguments(self, _):
context.argument('reviewers', nargs='*')
context.argument('detect', **enum_choice_list(_ON_OFF_SWITCH_VALUES))

with self.argument_context('repos policies create') as context:
context.argument('policy_type', **enum_choice_list(REPO_POLICY_TYPE))

with self.argument_context('repos pr') as context:
context.argument('description', type=str, options_list=('--description', '-d'), nargs='*')
context.argument('repository', options_list=('--repository', '-r'))
Expand Down
16 changes: 15 additions & 1 deletion azure-devops/azext_devops/dev/repos/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
transform_policies_table_output,
transform_policy_table_output,
transform_work_items_table_output,
transform_repo_import_table_output)
transform_repo_import_table_output,
transform_repo_policy_table_output,
transform_repo_policies_table_output)


reposPullRequestOps = CliCommandType(
Expand All @@ -28,6 +30,10 @@
operations_tmpl='azext_devops.dev.repos.import_request#{}'
)

policyOps = CliCommandType(
operations_tmpl='azext_devops.dev.repos.policy#{}'
)


def load_code_commands(self, _):
with self.command_group('repos', command_type=reposRepositoryOps) as g:
Expand All @@ -37,6 +43,14 @@ def load_code_commands(self, _):
g.command('list', 'list_repos', table_transformer=transform_repos_table_output)
g.command('show', 'show_repo', table_transformer=transform_repo_table_output)

with self.command_group('repos policies', command_type=policyOps) as g:
# repository/ branch policies
g.command('create', 'create_policy', table_transformer=transform_repo_policy_table_output)
g.command('list', 'list_policy', table_transformer=transform_repo_policies_table_output)
g.command('show', 'get_policy', table_transformer=transform_repo_policy_table_output)
g.command('update', 'update_policy', table_transformer=transform_repo_policy_table_output)
g.command('delete', 'delete_policy', confirmation='Are you sure you want to delete this policy?')

with self.command_group('repos pr', command_type=reposPullRequestOps) as g:
# basic pr commands
g.command('create', 'create_pull_request', table_transformer=transform_pull_request_table_output)
Expand Down
Loading