Skip to content

Commit

Permalink
Moved issue name validation to py script
Browse files Browse the repository at this point in the history
  • Loading branch information
SHIV5T3R committed Aug 29, 2024
1 parent 0270d6b commit ebc1efa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/generate_issue_number.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,8 @@ jobs:
application_id: ${{ secrets.app_id }}
application_private_key: ${{ secrets.app_key }}

- name: Check issue title
id: check_issue_title
run: |
ISSUE_TITLE=$(printf '%q' "${{ github.event.issue.title }}")
if [[ "$ISSUE_TITLE" =~ ^Y[0-9]{2}-[0-9]{3,4} ]]; then
echo "VALID_TITLE=true" >> $GITHUB_OUTPUT
else
echo "VALID_TITLE=false" >> $GITHUB_OUTPUT
fi
# Updates org variable for the counter & updates the issue title
- name: Assign custom issue number
if: steps.check_issue_title.outputs.VALID_TITLE == 'false'
uses: sanger/psd_story_number_generator@develop
with:
GITHUB_TOKEN: ${{ steps.get_workflow_token.outputs.token }}
Expand Down
13 changes: 12 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import os
import requests
import re


def check_issue_title(title):
if re.match(r'^Y[0-9]{2}-[0-9]{3,4}', title):
return False

return True

def get_org_variable(org, var_name, token):
url = f"https://api.github.com/orgs/{org}/actions/variables/{var_name}"
headers = {
Expand All @@ -14,7 +21,6 @@ def get_org_variable(org, var_name, token):
response.raise_for_status()

return response.json()["value"]


def update_org_variable(org, var_name, new_value, token):
url = f"https://api.github.com/orgs/{org}/actions/variables/{var_name}"
Expand Down Expand Up @@ -47,6 +53,7 @@ def update_issue_title(repo, issue_prefix, issue_number, token, next_number, iss
if response.status_code != 200:
print(f"Failed to update issue title: {response.json()}")


if __name__ == "__main__":
github_token = os.getenv('GITHUB_TOKEN')
repo = os.getenv('GITHUB_REPOSITORY')
Expand All @@ -56,6 +63,10 @@ def update_issue_title(repo, issue_prefix, issue_number, token, next_number, iss
issue_number = os.getenv('GITHUB_EVENT_ISSUE_NUMBER')
org_name = os.getenv('ORG_NAME')

if not check_issue_title(issue_title):
print(f"Invalid issue title: {issue_title}")
exit(0)

issue_counter = get_org_variable(org_name, issue_counter_var, github_token)
next_number = int(issue_counter) + 1
update_org_variable(org_name, issue_counter_var, next_number, github_token)
Expand Down

0 comments on commit ebc1efa

Please sign in to comment.