Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workflow: Force issue number mention in PR description and auto close… #3037

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

apoorvapendse
Copy link
Contributor

… issue.

Forces contributors to mention issue number they want to close via their PR in the PR description.

Once a PR is merged, the PR body is inspected to find the issue numbers that are addressed with the keywords Fixes/fixes, closes/Closes, Resolves/resolves followed by #<issue_number> and are closed accordingly.

Also created a basic PR template to make the contributors aware of this new change.

Closes #3032.

@DonnieBLT
Copy link
Collaborator

I would rather check with the tests that a linked GitHub issue exists using the new GitHub linked issue feature on the right of the plug request page: maybe something like this? I'm not sure how to access it this might work...


name: Check Linked Issue

on:
  pull_request:
    types: [opened, edited, reopened, synchronize]

jobs:
  check-linked-issue:
    runs-on: ubuntu-latest

    steps:
      # Checkout the code
      - name: Checkout repository
        uses: actions/checkout@v3

      # Verify linked issue
      - name: Verify Linked Issue
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          # Fetch the PR details from the GitHub API
          PR_URL="https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}"
          LINKED_ISSUES_URL=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" $PR_URL \
            | jq -r ._links.issue.href)

          # If the linked issues URL is null, there is no linked issue
          if [ "$LINKED_ISSUES_URL" == "null" ]; then
            echo "❌ No linked issue in the Linked Issue section."
            exit 1
          fi

          echo "✅ Pull request has a linked issue: $LINKED_ISSUES_URL"

@DonnieBLT
Copy link
Collaborator

This way it will close automatically when merged and there is less room for error.

@apoorvapendse
Copy link
Contributor Author

This way it will close automatically when merged and there is less room for error.

Yeah this seems like a better approach, I'll add this 👍

@apoorvapendse
Copy link
Contributor Author

apoorvapendse commented Dec 2, 2024

image
Screenshot from 2024-12-02 17-21-24

@DonnieBLT ,
I see some discrepancy with what the pull request references, it doesn't match the issues mentioned, rather contains the number of the PR itself in links.issue.href

The only place I find the actual issues being closed are in the body returned by the curl which is markdown which has be anyways parsed using regex.

Would like to know what you think we should do to progress.

@DonnieBLT
Copy link
Collaborator

image

@DonnieBLT
Copy link
Collaborator

Can we detect this?

@apoorvapendse
Copy link
Contributor Author

Can we detect this?

No, with the api url suggested, the actual issue can only be found through the body

@DonnieBLT
Copy link
Collaborator

Is there any other API that would work? How about we scrape the webpage?

@apoorvapendse
Copy link
Contributor Author

apoorvapendse commented Dec 2, 2024

Is there any other API that would work? How about we scrape the webpage?

GitHub uses keywords like close, closes, closed, fix, fixes, fixed, resolve, resolves, and resolved followed by the issue reference to automatically link the PR to the issue. The issue reference can be specified in various formats:

#<issue_number>: Refers to an issue in the same repository.

⬆️ as per google search

I think scraping would be over engineering, but if you think that's the best way to go forward, I'd be happy to implement it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add GitHub Action to Automatically Close Issues When PR is Merged
2 participants