project-beta-automations
project-beta-automations copied to clipboard
[BUG]
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:
- 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.
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
So is there any way we could move an issue like this?
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.
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
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.
Either is good for me :)
@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 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 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.
Thank you. I Would highly appreciate if you could comment on this discussion again and tag me when found a solution for that problem.
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 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.
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
}
}
}
}
}
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.
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 Reviewwhen PR isopened||ready_for_review||reopenedIn Progresswhen PR isconverted_to_draftDonewhen PR isclosedandmerged
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 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