diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 041c27623..149e2ed85 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -35,7 +35,7 @@ body: - type: dropdown id: os-family attributes: - label: OS + label: OS Family description: What operating system are you using to run the role? options: - RHEL (7.x, 8.x, 9.x) @@ -48,7 +48,7 @@ body: - type: textarea id: python-version attributes: - label: Python + label: Python version description: Please provide the python version you are using placeholder: 3.9.7 validations: @@ -57,7 +57,7 @@ body: - type: textarea id: ansible-version attributes: - label: Ansible-core + label: Ansible-core version description: Please provide the ansible-core version you are using placeholder: 2.12.0 validations: @@ -66,7 +66,7 @@ body: - type: textarea id: reproduction attributes: - label: Reproduction + label: How to reproduce the bug description: Please provide a way for us to be able to reproduce the problem you ran into. placeholder: Reproduction validations: @@ -88,20 +88,13 @@ body: id: additional attributes: label: Additional information - description: Do you intend to submit a pr to solve this bug? + description: Do you intend to submit a **Pull Request** to solve this bug? options: - - "Yes" - - "No" - default: 1 + - I can solve this bug + - I can't solve this bug validations: required: true - - type: textarea - id: additonal - attributes: - label: Additional context - description: If applicable, add any other context about the problem here - - type: checkboxes id: required-info attributes: @@ -110,5 +103,5 @@ body: options: - label: I've read [the documentation](https://github.com/sap-linuxlab/community.sap_install/tree/main/docs#readme). required: true - - label: I've already check for existing duplicated [issues](https://github.com/sap-linuxlab/community.sap_install/issues?q=is%3Aissue+label%3Abug). + - label: I've already checked for existing duplicated [issues](https://github.com/sap-linuxlab/community.sap_install/issues?q=is%3Aissue+label%3Abug). required: true diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index bba835f9c..5a53f960a 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -36,7 +36,7 @@ body: - type: dropdown id: os-family attributes: - label: OS + label: OS family description: For what operating systems family is the feature you want to propose meant to be? options: - RHEL (7.x, 8.x, 9.x) @@ -62,7 +62,7 @@ body: description: Do you want to implement this feature by yourself? options: - I can implement this feature - - I can't implement by myself this feature + - I can't/won't implement this feature validations: required: true diff --git a/.github/workflows/issue_checker.yml b/.github/workflows/issue_checker.yml new file mode 100644 index 000000000..a4cc3cc0f --- /dev/null +++ b/.github/workflows/issue_checker.yml @@ -0,0 +1,22 @@ +--- + +name: Issue automation title filler + +on: + issues: + types: [opened, edited, reopened] + +jobs: + check_outdate_dependencies: + runs-on: ubuntu-latest + + steps: + - name: Check out the code + uses: actions/checkout@v4 + + - name: Run issue check + uses: ./workflows/issue_checker + env: + GITHUB_REPOSITORY: ${{ github.repository }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + GITHUB_ISSUE_NUMBER: ${{ github.event.issue.number }} diff --git a/workflows/issue_checker/Dockerfile b/workflows/issue_checker/Dockerfile new file mode 100644 index 000000000..71f5e7013 --- /dev/null +++ b/workflows/issue_checker/Dockerfile @@ -0,0 +1,10 @@ +FROM python:slim + +COPY issue_checker.py /run.py +RUN chmod +x /run.py + +RUN pip3 install requests; \ + apt-get update; \ + apt-get install -y --no-install-recommends git + +ENTRYPOINT [ "/run.py" ] diff --git a/workflows/issue_checker/action.yml b/workflows/issue_checker/action.yml new file mode 100644 index 000000000..b3bfe0c25 --- /dev/null +++ b/workflows/issue_checker/action.yml @@ -0,0 +1,7 @@ +--- + +name: 'Issue automation title filler' +description: 'This action is trigger whenever a new issue is open and it update the title with the standard' +runs: + using: 'docker' + image: 'Dockerfile' diff --git a/workflows/issue_checker/issue_checker.py b/workflows/issue_checker/issue_checker.py new file mode 100644 index 000000000..94cfd3492 --- /dev/null +++ b/workflows/issue_checker/issue_checker.py @@ -0,0 +1,157 @@ +#!/usr/bin/env python + +import os +import sys +import requests +import re +import json + +TOKEN = str(os.environ.get("GITHUB_TOKEN")) +REPOSITORY = str(os.environ.get("GITHUB_REPOSITORY")) +ISSUE_NUMBER = str(os.environ.get("GITHUB_ISSUE_NUMBER")) +HEADERS = { + "Authorization": f"token {TOKEN}", + "Accept": "application/vnd.github+json" +} + +ISSUE_STANDARD_TITLE = r'^\[Bug|Feature\](?: [\w\s]+)?(?: on [\w\s]+)?: .+$' +ISSUE_ROLE_BODY = r'### Role\s+([\w_]+)' +ISSUE_OS_BODY = r'### OS Family\s+([\w_]+)' + +COMMENT_FOLLOW_STANDARD = """ +Hi, + +The standard for the issue title should be like this: `[Bug|Feature]: `. Please update the issue title to follow this standard. + +Example: +`[Bug]: pacemaker stop working on sles15` + +Thanks +""" +COMMENT_TITLE_NOT_ALIGNED = """ +Hi, + +It seems that the title and the labels are not aligned. Check if the label `bug` is selected if the issue is a Bug and the label `enhancement` is selected if is a Feature. + +Thanks +""" +COMMENT_MISS_SHORT_DESCRIPTION = """ +Hi, + +It seems that the title miss a short description. + +Could you please update the tile by adding something after the issue specification? + +Example: +`[Bug]: pacemaker stop working on sles15` + +Thanks +""" + + +def get_issue_descriptor(): + response = requests.get( + f"https://api.github.com/repos/{REPOSITORY}/issues/{ISSUE_NUMBER}", + headers=HEADERS) + if response.status_code == 200: + print(f"INFO: Issue found -> https://github.com/{REPOSITORY}/issues/{ISSUE_NUMBER}") + return response.json() + else: + print(f"ERROR: Failed to update the issue. Status code: {response.status_code}.") + return {} + + +def is_a_feature(labels): + for label in labels: + if label['name'] == 'enhancement': + return True + return False + + +def is_a_bug(labels): + for label in labels: + if label['name'] == 'bug': + return True + return False + + +def is_title_standardise(title): + regex_pattern = re.compile(ISSUE_STANDARD_TITLE) + matches = regex_pattern.findall(title) + + return False if not matches else True + + +def post_comment_on_issue(body): + comment_data = { + "body": body + } + response = requests.post( + f"https://api.github.com/repos/{REPOSITORY}/issues/{ISSUE_NUMBER}/comments", + headers=HEADERS, + data=json.dumps(comment_data)) + if response.status_code == 201: + print(f"INFO: Comment done in -> https://github.com/{REPOSITORY}/issues/{ISSUE_NUMBER}") + else: + print(f"ERROR: Failed to create comment. Status code: {response.status_code}.") + + +def update_title_on_issue(title): + title_data = { + "title": title + } + response = requests.post( + f"https://api.github.com/repos/{REPOSITORY}/issues/{ISSUE_NUMBER}", + headers=HEADERS, + data=json.dumps(title_data)) + if response.status_code == 200: + print(f"INFO: Title updated -> https://github.com/{REPOSITORY}/issues/{ISSUE_NUMBER}") + else: + print(f"ERROR: Failed to update title. Status code: {response.status_code}.") + + +def title_composer(issue_descriptor): + role_body = re.search(ISSUE_ROLE_BODY, issue_descriptor['body']) + os_body = re.search(ISSUE_OS_BODY, issue_descriptor['body']) + title_body = str.split(issue_descriptor['title'], ':') + + object_title = "" + description_title = "" + if title_body: + object_title = "" + str.split(title_body[0], ' ')[0] + description_title = "" + title_body[1] + + role_selected = "" + if role_body: + role_selected = " " + role_body.group(1) + + os_selected = "" + if os_body: + os_selected = " on " + os_body.group(1) + + return object_title + role_selected + os_selected + ":" + description_title + + +def is_short_description_filled(title): + return True if str.split(title, ':')[-1].strip(" ") else False + +if __name__ == '__main__': + issue_descriptor = get_issue_descriptor() + if issue_descriptor: + if not is_title_standardise(issue_descriptor['title']): + post_comment_on_issue(COMMENT_FOLLOW_STANDARD) + sys.exit(1) + + is_bug_not_bug = "Bug" in issue_descriptor['title'] and not is_a_bug(issue_descriptor['labels']) + is_feat_not_feat = "Feature" in issue_descriptor['title'] and not is_a_feature(issue_descriptor['labels']) + if is_bug_not_bug or is_feat_not_feat: + post_comment_on_issue(COMMENT_TITLE_NOT_ALIGNED) + sys.exit(1) + + if not is_short_description_filled(issue_descriptor['title']): + post_comment_on_issue(COMMENT_MISS_SHORT_DESCRIPTION) + sys.exit(1) + + title = title_composer(issue_descriptor) + if title != issue_descriptor['title']: + update_title_on_issue(title)