From aad0532114299916fdacd472ee04351905ac8678 Mon Sep 17 00:00:00 2001 From: Snailedlt <43886029+Snailedlt@users.noreply.github.com> Date: Sat, 15 Oct 2022 15:43:52 +0200 Subject: [PATCH 1/3] Check if PR base is develop fix #1458 --- .github/scripts/build_assets/api_handler.py | 28 +++++++++++++++++++++ .github/scripts/build_assets/arg_getters.py | 10 ++++++-- .github/scripts/check_icon_pr.py | 12 ++++++++- .github/workflows/check_icon_pr.yml | 9 ++++++- 4 files changed, 55 insertions(+), 4 deletions(-) diff --git a/.github/scripts/build_assets/api_handler.py b/.github/scripts/build_assets/api_handler.py index 042edb5ee..e3eb88b99 100644 --- a/.github/scripts/build_assets/api_handler.py +++ b/.github/scripts/build_assets/api_handler.py @@ -65,6 +65,34 @@ def get_merged_pull_reqs(token, page, log_output: FileIO=sys.stdout): if merged_pull_req["merged_at"] is not None] +def get_pull_req(token, pr_number): + """ + Get a PR based on the PR number + See https://docs.github.com/en/rest/pulls/pulls#get-a-pull-request for more details on the parameters. + :param token, a GitHub API token. + :param pr_number, the number of the pull request. + """ + url = f"{base_url}pulls/{pr_number}" + headers = { + "Authorization": f"token {token}" + } + response = requests.get(url, headers=headers) + if not response: + print(f"Can't query the GitHub API. Status code is {response.status_code}. Message is {response.text}") + sys.exit(1) + return response.json() + + + +def get_pr_base_branch(pull_req_data): + """ + Check whether the PR's base is develop. Meaning, if the PR is being committed to develop + :param pull_req_data - the data on a specific pull request from GitHub. + :return the base ref of the pull_req_data + """ + return pull_req_data["base"]["ref"] + + def is_feature_icon(pull_req_data): """ Check whether the pullData is a feature:icon PR. diff --git a/.github/scripts/build_assets/arg_getters.py b/.github/scripts/build_assets/arg_getters.py index d086bd331..2dbe0c5aa 100644 --- a/.github/scripts/build_assets/arg_getters.py +++ b/.github/scripts/build_assets/arg_getters.py @@ -4,7 +4,7 @@ def get_selenium_runner_args(peek_mode=False): """ - Get the commandline arguments for the icomoon_peek.py and + Get the commandline arguments for icomoon_peek.py and icomoon_build.py. """ parser = ArgumentParser(description="Upload svgs to Icomoon to create icon files.") @@ -45,13 +45,19 @@ def get_selenium_runner_args(peek_mode=False): def get_check_icon_pr_args(): """ - Get the commandline arguments for the check_icon_pr.py. + Get the commandline arguments for check_icon_pr.py. """ parser = ArgumentParser(description="Check the SVGs to ensure their attributes are correct. Run whenever a PR is opened") + parser.add_argument("token", + help="The GitHub token to access the GitHub REST API.") + parser.add_argument("pr_title", help="The title of the PR that we are peeking at") + parser.add_argument("pr_number", + help="The number of the PR that we are peeking at") + parser.add_argument("icons_folder_path", help="The path to the icons folder", action=PathResolverAction) diff --git a/.github/scripts/check_icon_pr.py b/.github/scripts/check_icon_pr.py index 40c6fe13c..b2081077a 100644 --- a/.github/scripts/check_icon_pr.py +++ b/.github/scripts/check_icon_pr.py @@ -5,7 +5,7 @@ # pycharm complains that build_assets is an unresolved ref # don't worry about it, the script still runs -from build_assets import filehandler, arg_getters, util +from build_assets import filehandler, arg_getters, util, api_handler def main(): @@ -16,6 +16,13 @@ def main(): """ args = arg_getters.get_check_icon_pr_args() try: + # check that the base branch of the PR is develop + pr_err_msg = "" + pr_data = api_handler.get_pull_req(args.token, args.pr_number) + pr_base_branch = api_handler.get_pr_base_branch(pr_data) + if pr_base_branch != "develop": + pr_err_msg = f"The PR's base branch is `{pr_base_branch}`, but should be `develop`, please change the PR so that it's based on, and merged into `develop`" + all_icons = filehandler.get_json_file_content(args.devicon_json_path) # get only the icon object that has the name matching the pr title @@ -40,6 +47,9 @@ def main(): svg_err_msg = check_svgs(svgs) err_msg = [] + if pr_err_msg != "": + err_msg.append(pr_err_msg) + if devicon_err_msg != "": err_msg.append(devicon_err_msg) diff --git a/.github/workflows/check_icon_pr.yml b/.github/workflows/check_icon_pr.yml index 6a57bab49..59a2edcf0 100644 --- a/.github/workflows/check_icon_pr.yml +++ b/.github/workflows/check_icon_pr.yml @@ -12,10 +12,17 @@ jobs: with: python-version: 3.8 + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r ./.github/scripts/requirements.txt + - name: Run the check_svg script env: + TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_TITLE: ${{ github.event.pull_request.title }} - run: python ./.github/scripts/check_icon_pr.py "$PR_TITLE" ./icons ./devicon.json + PR_NUMBER: ${{ github.event.number }} + run: python ./.github/scripts/check_icon_pr.py "$TOKEN" "$PR_TITLE" "$PR_NUMBER" ./icons ./devicon.json - name: Upload the err messages uses: actions/upload-artifact@v2 From d04288080138f4d35c4002fa50a80c5597122eda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9lio=20J=C3=BAnior?= <76992016+lunatic-fox@users.noreply.github.com> Date: Wed, 30 Nov 2022 02:16:29 -0300 Subject: [PATCH 2/3] Add PR base checker --- .github/workflows/check_icon_pr.yml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check_icon_pr.yml b/.github/workflows/check_icon_pr.yml index 59a2edcf0..8aa9dccde 100644 --- a/.github/workflows/check_icon_pr.yml +++ b/.github/workflows/check_icon_pr.yml @@ -7,17 +7,26 @@ jobs: if: startsWith(github.event.pull_request.title, 'new icon') || startsWith(github.event.pull_request.title, 'update icon') # only checks icon PR steps: - uses: actions/checkout@v2 + + - name: Check if PR is develop + if: ${{ github.base_ref != 'develop' }} + run: | + echo -e "The PR's base branch is \`${{ github.base_ref }}\`, but should be \`develop\`\nPlease change the PR so that it's based on, and merged into \`develop\`" > ./err_messages.txt + echo "wrong_branch=true" >> $GITHUB_ENV - uses: actions/setup-python@v2 + if: ${{ !env.wrong_branch }} with: python-version: 3.8 - - name: Install dependencies + - name: Install dependencies + if: ${{ !env.wrong_branch }} run: | python -m pip install --upgrade pip pip install -r ./.github/scripts/requirements.txt - name: Run the check_svg script + if: ${{ !env.wrong_branch }} env: TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_TITLE: ${{ github.event.pull_request.title }} From 84a8e4c0781e663cbfdefdd6b3b97c070e27a341 Mon Sep 17 00:00:00 2001 From: Snailedlt <43886029+Snailedlt@users.noreply.github.com> Date: Sun, 11 Dec 2022 22:48:06 +0100 Subject: [PATCH 3/3] Revert "Check if PR base is develop" This reverts commit aad0532114299916fdacd472ee04351905ac8678. --- .github/scripts/build_assets/api_handler.py | 28 --------------------- .github/scripts/build_assets/arg_getters.py | 10 ++------ .github/scripts/check_icon_pr.py | 12 +-------- .github/workflows/check_icon_pr.yml | 4 +-- 4 files changed, 4 insertions(+), 50 deletions(-) diff --git a/.github/scripts/build_assets/api_handler.py b/.github/scripts/build_assets/api_handler.py index e3eb88b99..042edb5ee 100644 --- a/.github/scripts/build_assets/api_handler.py +++ b/.github/scripts/build_assets/api_handler.py @@ -65,34 +65,6 @@ def get_merged_pull_reqs(token, page, log_output: FileIO=sys.stdout): if merged_pull_req["merged_at"] is not None] -def get_pull_req(token, pr_number): - """ - Get a PR based on the PR number - See https://docs.github.com/en/rest/pulls/pulls#get-a-pull-request for more details on the parameters. - :param token, a GitHub API token. - :param pr_number, the number of the pull request. - """ - url = f"{base_url}pulls/{pr_number}" - headers = { - "Authorization": f"token {token}" - } - response = requests.get(url, headers=headers) - if not response: - print(f"Can't query the GitHub API. Status code is {response.status_code}. Message is {response.text}") - sys.exit(1) - return response.json() - - - -def get_pr_base_branch(pull_req_data): - """ - Check whether the PR's base is develop. Meaning, if the PR is being committed to develop - :param pull_req_data - the data on a specific pull request from GitHub. - :return the base ref of the pull_req_data - """ - return pull_req_data["base"]["ref"] - - def is_feature_icon(pull_req_data): """ Check whether the pullData is a feature:icon PR. diff --git a/.github/scripts/build_assets/arg_getters.py b/.github/scripts/build_assets/arg_getters.py index 2dbe0c5aa..d086bd331 100644 --- a/.github/scripts/build_assets/arg_getters.py +++ b/.github/scripts/build_assets/arg_getters.py @@ -4,7 +4,7 @@ def get_selenium_runner_args(peek_mode=False): """ - Get the commandline arguments for icomoon_peek.py and + Get the commandline arguments for the icomoon_peek.py and icomoon_build.py. """ parser = ArgumentParser(description="Upload svgs to Icomoon to create icon files.") @@ -45,19 +45,13 @@ def get_selenium_runner_args(peek_mode=False): def get_check_icon_pr_args(): """ - Get the commandline arguments for check_icon_pr.py. + Get the commandline arguments for the check_icon_pr.py. """ parser = ArgumentParser(description="Check the SVGs to ensure their attributes are correct. Run whenever a PR is opened") - parser.add_argument("token", - help="The GitHub token to access the GitHub REST API.") - parser.add_argument("pr_title", help="The title of the PR that we are peeking at") - parser.add_argument("pr_number", - help="The number of the PR that we are peeking at") - parser.add_argument("icons_folder_path", help="The path to the icons folder", action=PathResolverAction) diff --git a/.github/scripts/check_icon_pr.py b/.github/scripts/check_icon_pr.py index b2081077a..40c6fe13c 100644 --- a/.github/scripts/check_icon_pr.py +++ b/.github/scripts/check_icon_pr.py @@ -5,7 +5,7 @@ # pycharm complains that build_assets is an unresolved ref # don't worry about it, the script still runs -from build_assets import filehandler, arg_getters, util, api_handler +from build_assets import filehandler, arg_getters, util def main(): @@ -16,13 +16,6 @@ def main(): """ args = arg_getters.get_check_icon_pr_args() try: - # check that the base branch of the PR is develop - pr_err_msg = "" - pr_data = api_handler.get_pull_req(args.token, args.pr_number) - pr_base_branch = api_handler.get_pr_base_branch(pr_data) - if pr_base_branch != "develop": - pr_err_msg = f"The PR's base branch is `{pr_base_branch}`, but should be `develop`, please change the PR so that it's based on, and merged into `develop`" - all_icons = filehandler.get_json_file_content(args.devicon_json_path) # get only the icon object that has the name matching the pr title @@ -47,9 +40,6 @@ def main(): svg_err_msg = check_svgs(svgs) err_msg = [] - if pr_err_msg != "": - err_msg.append(pr_err_msg) - if devicon_err_msg != "": err_msg.append(devicon_err_msg) diff --git a/.github/workflows/check_icon_pr.yml b/.github/workflows/check_icon_pr.yml index 8aa9dccde..eb128cc36 100644 --- a/.github/workflows/check_icon_pr.yml +++ b/.github/workflows/check_icon_pr.yml @@ -28,10 +28,8 @@ jobs: - name: Run the check_svg script if: ${{ !env.wrong_branch }} env: - TOKEN: ${{ secrets.GITHUB_TOKEN }} PR_TITLE: ${{ github.event.pull_request.title }} - PR_NUMBER: ${{ github.event.number }} - run: python ./.github/scripts/check_icon_pr.py "$TOKEN" "$PR_TITLE" "$PR_NUMBER" ./icons ./devicon.json + run: python ./.github/scripts/check_icon_pr.py "$PR_TITLE" ./icons ./devicon.json - name: Upload the err messages uses: actions/upload-artifact@v2