-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
65953d1
commit c3523ad
Showing
3 changed files
with
71 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import argparse | ||
import subprocess | ||
import json | ||
|
||
def constant(f): | ||
def fset(self, value): | ||
raise TypeError | ||
def fget(self): | ||
return f() | ||
return property(fget, fset) | ||
|
||
class _Const(object): | ||
@constant | ||
def GET_PR_DETAILS_CLI_COMMAND() -> str: | ||
return 'gh pr list --json body --repo {repository} --state merged --search {commit_sha}' | ||
|
||
CONST = _Const() | ||
|
||
def parseArguments(): | ||
parser = argparse.ArgumentParser(description="Utility to tag ADO workitem with deployment environemnt", exit_on_error=False) | ||
parser.add_argument('--gh-token', type=str, required=False, dest='gh_token') | ||
parser.add_argument('--repository', type=str, required=True, dest='repository') | ||
parser.add_argument('--commit-sha', type=str, required=True, dest='commit_sha') | ||
return parser.parse_args() | ||
|
||
def extractAdoReferenceFromPR(args): | ||
prData = subprocess.run(CONST.GET_PR_DETAILS_CLI_COMMAND.format(repository = args.repository, commit_sha = args.commit_sha), capture_output=True, shell=True, text=True) | ||
if prData.returncode != 0: | ||
raise Exception('Failed to retrieve PR body for commit identified by {} SHA'.format(args.commit_sha)) | ||
prBody = json.loads(prData.stdout)[0]['body'] | ||
print(prBody) | ||
|
||
|
||
def main(): | ||
args = parseArguments() | ||
extractAdoReferenceFromPR(args) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |