Loading .github/pr_label_checker.py +8 −12 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ def get_pr_attributes(response: Response) -> tuple: Get necessary PR attributes. """ pull_response_json = response.json() if len(pull_response_json) == 0: if not pull_response_json: # No PRs attributed to the commit print(False) sys.exit(0) Loading @@ -64,6 +64,7 @@ def search_for_linked_issues(pull_body: str) -> list: # Split the PR body by heading pull_body_list = pull_body.split('##') regex_pattern = rf'{ISSUES_URL}(\d)|(#[^\D]\d*)' issue_numbers = [] for section in pull_body_list: # Find section with heading 'Related Issue' if section != None and 'Related Issue' in section: Loading @@ -76,9 +77,6 @@ def search_for_linked_issues(pull_body: str) -> list: # Remove '#' from items issue_numbers = list(map(lambda item: item.replace('#', ''), filtered_list)) return issue_numbers # No linked issues print(False) sys.exit(0) def get_linked_issues(issue_numbers: list) -> list: Loading Loading @@ -113,10 +111,6 @@ def get_issue_labels(response_list: list) -> list: if label_name not in combined_issue_labels: # Add label if it does not exist combined_issue_labels.append(label_name) if not combined_issue_labels: # No labels to return print(False) sys.exit(0) return combined_issue_labels def update_pr_labels(pull_number: str, combined_issue_labels: list): Loading Loading @@ -163,8 +157,10 @@ if __name__ == "__main__": response = get_prs_associated_with_commit() pull_number, pull_body = get_pr_attributes(response) issue_numbers = search_for_linked_issues(pull_body) if issue_numbers: response_list = get_linked_issues(issue_numbers) combined_issue_labels = get_issue_labels(response_list) if combined_issue_labels: update_pr_labels(pull_number, combined_issue_labels) # Check if PR is a bugfix Loading .github/workflows/gitlab-lts.yml 0 → 100644 +66 −0 Original line number Diff line number Diff line name: Github to Gitlab CI - Run CodeBuild (LTS) env: GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }} on: push: branches: - lts-testing #dev jobs: # Check if the PR is a bugfix check_labels: runs-on: ubuntu-latest permissions: pull-requests: write name: Check PR labels action step # Make the output of this job available to other jobs outputs: result: ${{steps.execute_py_script.outputs.result}} steps: - name: checkout repo content uses: actions/checkout@v2 # checkout the repository content - name: setup python uses: actions/setup-python@v4 with: python-version: '3.10' cache: 'pip' - name: install python packages run: | python -m pip install --upgrade pip pip install -r ./.github/requirements.txt - name: Set output id: execute_py_script env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_API_URL: ${{ secrets.GITHUB_API_URL }} GITHUB_SERVER_URL: ${{ secrets.GITHUB_SERVER_URL }} GITHUB_SHA: ${{ secrets.GITHUB_SHA }} run: | echo "result=$(python ./.github/pr_label_checker.py)" >> $GITHUB_OUTPUT # Print the result to the log - name: See result run: echo "${{ steps.execute_py_script.outputs.result }}" build: needs: check_labels # Only run this step if the code was a bugfix if: contains(needs.check_labels.outputs.result, 'true') runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run script env: ISIS_VERSION: 8.0.5-LTS-test #${{ github.event.release.tag_name || github.ref_name }} GITHUB_SHA: ${{ secrets.GITHUB_SHA }} run: | git config --global user.name "Github_CI" git config --global user.email "project_14468_bot_3f7d8e1a392afd88ead5f3f3154e809d@noreply.gitlab.com" git clone https://isis-codebuild-ci:$GITLAB_TOKEN@code.usgs.gov/astrogeology/isis-codebuild-ci.git echo $ISIS_VERSION cd isis-codebuild-ci git checkout -b $ISIS_VERSION echo -e "\nenv: \n shell: bash \n variables: \n ISIS_VERSION: $ISIS_VERSION \n ANACONDA_API_TOKEN: $ANACONDA_TOKEN \n GITHUB_SHA: $GITHUB_SHA" >> buildspec-lts.yml git commit -a -m "$ISIS_VERSION" git push origin $ISIS_VERSION --force Loading
.github/pr_label_checker.py +8 −12 Original line number Diff line number Diff line Loading @@ -42,7 +42,7 @@ def get_pr_attributes(response: Response) -> tuple: Get necessary PR attributes. """ pull_response_json = response.json() if len(pull_response_json) == 0: if not pull_response_json: # No PRs attributed to the commit print(False) sys.exit(0) Loading @@ -64,6 +64,7 @@ def search_for_linked_issues(pull_body: str) -> list: # Split the PR body by heading pull_body_list = pull_body.split('##') regex_pattern = rf'{ISSUES_URL}(\d)|(#[^\D]\d*)' issue_numbers = [] for section in pull_body_list: # Find section with heading 'Related Issue' if section != None and 'Related Issue' in section: Loading @@ -76,9 +77,6 @@ def search_for_linked_issues(pull_body: str) -> list: # Remove '#' from items issue_numbers = list(map(lambda item: item.replace('#', ''), filtered_list)) return issue_numbers # No linked issues print(False) sys.exit(0) def get_linked_issues(issue_numbers: list) -> list: Loading Loading @@ -113,10 +111,6 @@ def get_issue_labels(response_list: list) -> list: if label_name not in combined_issue_labels: # Add label if it does not exist combined_issue_labels.append(label_name) if not combined_issue_labels: # No labels to return print(False) sys.exit(0) return combined_issue_labels def update_pr_labels(pull_number: str, combined_issue_labels: list): Loading Loading @@ -163,8 +157,10 @@ if __name__ == "__main__": response = get_prs_associated_with_commit() pull_number, pull_body = get_pr_attributes(response) issue_numbers = search_for_linked_issues(pull_body) if issue_numbers: response_list = get_linked_issues(issue_numbers) combined_issue_labels = get_issue_labels(response_list) if combined_issue_labels: update_pr_labels(pull_number, combined_issue_labels) # Check if PR is a bugfix Loading
.github/workflows/gitlab-lts.yml 0 → 100644 +66 −0 Original line number Diff line number Diff line name: Github to Gitlab CI - Run CodeBuild (LTS) env: GITLAB_TOKEN: ${{ secrets.GITLAB_TOKEN }} ANACONDA_TOKEN: ${{ secrets.ANACONDA_TOKEN }} on: push: branches: - lts-testing #dev jobs: # Check if the PR is a bugfix check_labels: runs-on: ubuntu-latest permissions: pull-requests: write name: Check PR labels action step # Make the output of this job available to other jobs outputs: result: ${{steps.execute_py_script.outputs.result}} steps: - name: checkout repo content uses: actions/checkout@v2 # checkout the repository content - name: setup python uses: actions/setup-python@v4 with: python-version: '3.10' cache: 'pip' - name: install python packages run: | python -m pip install --upgrade pip pip install -r ./.github/requirements.txt - name: Set output id: execute_py_script env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_API_URL: ${{ secrets.GITHUB_API_URL }} GITHUB_SERVER_URL: ${{ secrets.GITHUB_SERVER_URL }} GITHUB_SHA: ${{ secrets.GITHUB_SHA }} run: | echo "result=$(python ./.github/pr_label_checker.py)" >> $GITHUB_OUTPUT # Print the result to the log - name: See result run: echo "${{ steps.execute_py_script.outputs.result }}" build: needs: check_labels # Only run this step if the code was a bugfix if: contains(needs.check_labels.outputs.result, 'true') runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Run script env: ISIS_VERSION: 8.0.5-LTS-test #${{ github.event.release.tag_name || github.ref_name }} GITHUB_SHA: ${{ secrets.GITHUB_SHA }} run: | git config --global user.name "Github_CI" git config --global user.email "project_14468_bot_3f7d8e1a392afd88ead5f3f3154e809d@noreply.gitlab.com" git clone https://isis-codebuild-ci:$GITLAB_TOKEN@code.usgs.gov/astrogeology/isis-codebuild-ci.git echo $ISIS_VERSION cd isis-codebuild-ci git checkout -b $ISIS_VERSION echo -e "\nenv: \n shell: bash \n variables: \n ISIS_VERSION: $ISIS_VERSION \n ANACONDA_API_TOKEN: $ANACONDA_TOKEN \n GITHUB_SHA: $GITHUB_SHA" >> buildspec-lts.yml git commit -a -m "$ISIS_VERSION" git push origin $ISIS_VERSION --force