isaacs / github

Just a place to track issues and feature requests that I have for github
2.21k stars 129 forks source link

Automatic Issue Linking not working #2025

Closed SerenModz21 closed 3 years ago

SerenModz21 commented 3 years ago

Hello. I was wondering if anyone knows why GitHub is not automatically linking the pull request with the issue. I am trying to use GitHub actions to automatically link issues with a specific pull request from gaining a label called "done".

From looking at GitHub Documentation (link here), It shows that these keywords can be used to link them together but it isn't working.

Image

If needed, here is the code for the GitHub action:

name: Label Automation

on:
  issues:
    types: [labeled]

jobs:
  automation:
    runs-on: ubuntu-latest
    name: Label Automation
    steps:
      - name: Checkout Project
        uses: actions/checkout@v2

      - name: Assign done label
        if: ${{ github.event.label.name == 'done' }}
        uses: peter-evans/create-or-update-comment@v1
        with:
          issue-number: 80
          token: ${{ secrets.GITHUB_TOKEN }}
          body: |
            ## The issue was marked as done
            - Resolve #${{ github.event.issue.number }}
            - Closes #${{ github.event.issue.number }}
            - Resolves #${{ github.event.issue.number }}
github-actions[bot] commented 3 years ago

GitHub staff are eager to continue in conversations and knowledge-sharing with you. We invite you to head over to Feedback Discussions and share your product feedback and questions directly with us (noted here). Once you have added your thoughts in Feedback Discussions, we ask that you close this newly-created issue. Otherwise, we will keep this issue open for the next 7 days, then will close it.

Levi-Lesches commented 3 years ago

They need to be in the original post of the PR, not the follow-up comments.

You either want to have the bot edit the original post of the PR, if possible, maybe by appending a line after with "Closes #issue". Or if you tell me a bit more about your use-case, I can help think of a different way.

Interestingly, the API doesn't have a way to manually link issues to PRs, even though you can through the API.

SerenModz21 commented 3 years ago

They need to be in the original post of the PR, not the follow-up comments.

You either want to have the bot edit the original post of the PR, if possible, maybe by appending a line after with "Closes #issue". Or if you tell me a bit more about your use-case, I can help think of a different way.

Interestingly, the API doesn't have a way to manually link issues to PRs, even though you can through the API.

The use-case is that when a label called "done" is added to an issue, I want the issue to automatically get linked with the provided pull request. I want to do this so I don't need to keep manually linking them together.

Levi-Lesches commented 3 years ago

If you Seems like you can use Update a Pull request to edit the PR to say "Fixes #issue". I couldn't find an action on the GitHub Marketplace after a quick search, but More Linked Issues does something similar, so you may be able to copy their code and modify it to use your PR number. To quote from the "Behavior" section:

GitHub does not currently (as of October 15, 2020) offer an API to link issues to pull requests. To establish the links, more-linked-issues-action appends a short section of text to the end of the pull request body (its "description"). This text contains:

  • a markdown separator
  • a list of issue references, each preceded by a GitHub-approved keyword ("Resolves")
  • an "updated on" timestamp and link to this action's homepage

The text uses a pair of HTML comments to declare its sandbox; these comments will be found upon re-run and the be removed and/or updated as appropriate.

Warning: Do not change the comments, or you will likely get duplicated information. If this happens, delete all of it manually; if the edited type is enabled for the pull_request event (see example below), it will trigger the action again.

If more-linked-issues-action previously found links, but does not find any upon re-run, it will remove the section. If it previosuly found multiple links, but some subset is not found upon re-run, it will remove the stale links from the section.

SerenModz21 commented 3 years ago

Thank you for your help! I will give those a try.