Skip to content

Commit

Permalink
change to python
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasSielski committed Sep 12, 2024
1 parent 65953d1 commit ecf7b47
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 24 deletions.
53 changes: 29 additions & 24 deletions .github/workflows/actions/ado_tag/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,35 @@ inputs:
runs:
using: composite
steps:
- name: Get PR's body for commit identified by ${{ inputs.commit-sha }} SHA
id: get-pr-body
env:
- env:
GH_TOKEN: ${{ inputs.gh-token }}
run: |
PRBODY=$(gh pr list --json body --repo ${{ inputs.repository }} --state merged --search ${{ inputs.commit-sha }} --jq '.[].body')
echo "PRs body: $PRBODY"
echo "PRBODY=${PRBODY}" >> $GITHUB_ENV
shell: bash
- name: Extract work item reference number from PR's body
id: extract-reference-number
run: |
reference_num=$(echo $PRBODY | sed -n "s/^.*AB#\([0-9]*\).*$/\1/p")
if [ -z "$reference_num" ]
then
echo "Reference number not found!"
exit 1
else
echo "Reference number is $reference_num"
echo "REFERENCE=${reference_num}" >> $GITHUB_ENV
fi
shell: bash
- name: Add env tag for workitem
id: tag-workitem
run: |
echo "Going to add tag ${{ inputs.deploy_env }} to a work item identified by $REFERENCE number."
shell: bash
python /home/runner/work/workflows_tests/workflows_tests/scripts/script.py --repository ${{ inputs.repository }} --commit-sha ${{ inputs.commit-sha }}
# - name: Get PR's body for commit identified by ${{ inputs.commit-sha }} SHA
# id: get-pr-body
# env:
# GH_TOKEN: ${{ inputs.gh-token }}
# run: |
# PRBODY=$(gh pr list --json body --repo ${{ inputs.repository }} --state merged --search ${{ inputs.commit-sha }} --jq '.[].body')
# echo "PRs body: $PRBODY"
# echo "PRBODY=${PRBODY}" >> $GITHUB_ENV
# shell: bash
# - name: Extract work item reference number from PR's body
# id: extract-reference-number
# run: |
# reference_num=$(echo $PRBODY | sed -n "s/^.*AB#\([0-9]*\).*$/\1/p")
# if [ -z "$reference_num" ]
# then
# echo "Reference number not found!"
# exit 1
# else
# echo "Reference number is $reference_num"
# echo "REFERENCE=${reference_num}" >> $GITHUB_ENV
# fi
# shell: bash
# - name: Add env tag for workitem
# id: tag-workitem
# run: |
# echo "Going to add tag ${{ inputs.deploy_env }} to a work item identified by $REFERENCE number."
# shell: bash
36 changes: 36 additions & 0 deletions scripts/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import argparse
import subprocess

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 setupArgumentsParsing():
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(args=[CONST.GET_PR_DETAILS_CLI_COMMAND.format(repository = args.repository, commit_sha = args.commit_sha)], capture_output=True, shell=True, text=True)
print(prData)


def main():
args = setupArgumentsParsing()
extractAdoReferenceFromPR(args)


if __name__ == '__main__':
main()

0 comments on commit ecf7b47

Please sign in to comment.