project-beta-automations icon indicating copy to clipboard operation
project-beta-automations copied to clipboard

[BUG]

Open FortitudeIT opened this issue 3 years ago • 7 comments

Describe the bug I am trying to move an issue to "In review" on the project board, but it's not moving. My guess is that it's because the PR isn't the same as the issue id?

To Reproduce Steps to reproduce the behavior:

  1. Define the workflow steps with values like
name: Project automations
on:
  issues:
    types:
      - opened
      - reopened
      - closed
  pull_request:
    types:
      - opened
      - reopened
      - review_requested
      - closed

# map fields with customized labels
env:
  backlog: Backlog
  in_progress: 🏗 In progress
  testing: Testing
  in_review: In review
  done: Done ✅

jobs:
  pr_opened_or_reopened_or_reviewrequested:
    name: pr_opened_or_reopened_or_reviewrequested
    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request' && (github.event.action == 'opened' || github.event.action == 'reopened' || github.event.action == 'review_requested')
    steps:
      - name: Move PR to ${{ env.testing }}
        uses: leonsteinhaeuser/[email protected]
        with:
          gh_token: xxxx
          organization: abc
          project_id: 3
          resource_node_id: ${{ github.event.pull_request.node_id }}
          status_value: ${{ env.testing }} # Target status

Expected behavior The issue is moved to the "In review" lane.

FortitudeIT avatar Aug 17 '22 11:08 FortitudeIT

Your guess is correct. The issue ID is not the same as the pull request ID. You can take a look at the workflow file that manages this repository:

https://github.com/leonsteinhaeuser/project-beta-automations/blob/main/.github/workflows/project_automations.yml

leonsteinhaeuser avatar Aug 19 '22 21:08 leonsteinhaeuser

So is there any way we could move an issue like this?

FortitudeIT avatar Aug 21 '22 14:08 FortitudeIT

I don't know what the pull_request context contains in terms of information, but maybe it is possible to get the linked issue via that context.

leonsteinhaeuser avatar Aug 21 '22 16:08 leonsteinhaeuser

They're linked in URLs, but I don't think they're in the response itself, so you'd have to do another API call.

https://docs.github.com/en/rest/pulls/pulls#list-pull-requests

FortitudeIT avatar Aug 25 '22 12:08 FortitudeIT

Thanks for investigating the API. This basically allows us to scrape the attached issues from the PR. I'm not sure if this should be covered in this automation, but it could be an interesting feature. If you want, I can suggest a solution that does not require changing the automation.

Otherwise, it will take some time because GitHub has changed the project API, forcing me to basically rewrite some things (v2). After this rewrite is done, I could start implementing this functionality.

leonsteinhaeuser avatar Aug 25 '22 13:08 leonsteinhaeuser

Either is good for me :)

FortitudeIT avatar Sep 01 '22 12:09 FortitudeIT

@FortitudeIT I invested some time in the past day's, but couldn't fight a reliable solution so far. Going to investigate it further, unless you found a solution.

leonsteinhaeuser avatar Sep 26 '22 21:09 leonsteinhaeuser

@leonsteinhaeuser no solution found yet? Having the same issue. There has to be a way to move issues and not only pull requests right?

anrico-oltmanns avatar Nov 23 '22 10:11 anrico-oltmanns

@anrico-oltmanns I have already invested some time to find a solution to this problem. So far I have not had any luck. The problem is that the links I want are not included in the event response I received from the server (ci-workflow). The only solution I have left is to create more API requests and hope that the response will contain the necessary information.

When I have some time, I will take another look and implement this feature.

leonsteinhaeuser avatar Nov 23 '22 11:11 leonsteinhaeuser

Thank you. I Would highly appreciate if you could comment on this discussion again and tag me when found a solution for that problem.

anrico-oltmanns avatar Nov 23 '22 12:11 anrico-oltmanns

Status update:

The following two files contain the response that the GitHub server sends when I request the value for a particular pull request.

The first one contains the link to the issue in the body field (plain text), the second one does not contain the information at all.

pr_linked_with_comment.json.log pr_linked_without_comment.json.log

I will investigate this further.

leonsteinhaeuser avatar Nov 30 '22 14:11 leonsteinhaeuser

@leonsteinhaeuser I am really interested in this automation also, ie. I want my issues to be moved into PR Review column when there is a PR created, and it has in his body the issue_id with an issue link keyword, ie Resolves #ID_OF_ISSUE

I found this action: https://github.com/1natsu172/github-action-auto-move-related-issue but unfortunately it works only in old github projects, maybe it can help you to look at the implementation. I created an issue there, but it seems the project is discontinued.

mustafaozhan avatar Dec 19 '22 11:12 mustafaozhan

Hello everyone, I'm sorry it took me so long to respond. In the last few days I had some time to study GitHub's GraphQL API. In doing so, I found out that GitHub supports the "ClosingIssuesReferences" object reference in pull requests.

This functionality would allow me to simply select the linked issues that would be closed by the desired pull request. A list of keywords for closing can be found here.

In the next few days I will create a first version that we can test to see how it works.

Example GraphQL code:

    local REPO=$2
    local OWNER=$3
    gh api graphql -f query='
    query($owner: String!, $repo: String!) {
      repository(owner: $owner, name: $repo) {
        pullRequest(number: 21) {
          id
          closingIssuesReferences(first: 100) {
            nodes {
                id
                number
                title
            }
            totalCount
          }
        }
      }
    }' -f owner=$OWNER -f repo=$REPO

Response:

{
  "data": {
    "repository": {
      "pullRequest": {
        "id": "PR_kwDOGWypss5KPRmJ",
        "closingIssuesReferences": {
          "nodes": [
            {
              "id": "I_kwDOGWypss5exRM8",
              "number": 28,
              "title": "[BUG]: 1"
            }
          ],
          "totalCount": 1
        }
      }
    }
  }
}

leonsteinhaeuser avatar Feb 19 '23 15:02 leonsteinhaeuser

Can someone please verify that the new behavior works as you would expect?

You can test this by defining the workflow as follows:

  pr_closed:
    name: pr_closed
    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request' && github.event.action == 'closed'
    env:
      done: "Done"
    steps:
      - name: Move PR to ${{ env.done }}
        uses: leonsteinhaeuser/project-beta-automations@feat/move-related-issues
        with:
          gh_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          user: sample-user
          # organization: sample-org
          project_id: 1
          resource_node_id: ${{ github.event.pull_request.node_id }}
          status_value: ${{ env.done }}
          move_related_issues: true

Once you specify one of the GitHub link options, the issue should be moved along with the pull request.

leonsteinhaeuser avatar Feb 22 '23 13:02 leonsteinhaeuser

Hello @leonsteinhaeuser

I confirm that it works!

As an example, I put my PR changes here: https://github.com/Oztechan/CCC/pull/2099/files

I was able to move related issue to

  • PR Review when PR is opened || ready_for_review || reopened
  • In Progress when PR is converted_to_draft
  • Done when PR is closed and merged

Last one is important, we should not invoke it only when is closed, but we need to check if it is merged or not. I check the documentation and found best way to do it is:

if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true

mustafaozhan avatar Feb 23 '23 08:02 mustafaozhan

@mustafaozhan thanks for the confirmation. I have merged the pull request and created a new release https://github.com/leonsteinhaeuser/project-beta-automations/releases/tag/v2.1.0

leonsteinhaeuser avatar Feb 23 '23 20:02 leonsteinhaeuser