1
0
mirror of https://github.com/konpa/devicon.git synced 2025-08-29 17:20:09 +02:00

Check if PR base is develop

fix #1458
This commit is contained in:
Snailedlt
2022-10-15 15:43:52 +02:00
parent 300685abbf
commit aad0532114
4 changed files with 55 additions and 4 deletions

View File

@@ -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] 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): def is_feature_icon(pull_req_data):
""" """
Check whether the pullData is a feature:icon PR. Check whether the pullData is a feature:icon PR.

View File

@@ -4,7 +4,7 @@ from build_assets.PathResolverAction import PathResolverAction
def get_selenium_runner_args(peek_mode=False): 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. icomoon_build.py.
""" """
parser = ArgumentParser(description="Upload svgs to Icomoon to create icon files.") 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(): 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 = 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", parser.add_argument("pr_title",
help="The title of the PR that we are peeking at") 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", parser.add_argument("icons_folder_path",
help="The path to the icons folder", help="The path to the icons folder",
action=PathResolverAction) action=PathResolverAction)

View File

@@ -5,7 +5,7 @@ from pathlib import Path
# pycharm complains that build_assets is an unresolved ref # pycharm complains that build_assets is an unresolved ref
# don't worry about it, the script still runs # 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(): def main():
@@ -16,6 +16,13 @@ def main():
""" """
args = arg_getters.get_check_icon_pr_args() args = arg_getters.get_check_icon_pr_args()
try: 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) all_icons = filehandler.get_json_file_content(args.devicon_json_path)
# get only the icon object that has the name matching the pr title # 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) svg_err_msg = check_svgs(svgs)
err_msg = [] err_msg = []
if pr_err_msg != "":
err_msg.append(pr_err_msg)
if devicon_err_msg != "": if devicon_err_msg != "":
err_msg.append(devicon_err_msg) err_msg.append(devicon_err_msg)

View File

@@ -12,10 +12,17 @@ jobs:
with: with:
python-version: 3.8 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 - name: Run the check_svg script
env: env:
TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_TITLE: ${{ github.event.pull_request.title }} 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 - name: Upload the err messages
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2