-
I have these in my yml file:
But since the one who issues the comment may not be the PR author, the In other words, how do we get the PR author when a random person issues a comment? |
Beta Was this translation helpful? Give feedback.
Replies: 15 comments 1 reply
-
When a workflow run is triggered by the events related to pull request, from the github context of this run you can see the “github.event.pull_request” object. In this object, you can use the property “github.event.pull_request.user.login” to get the author who opened this PR.
|
Beta Was this translation helpful? Give feedback.
-
Thanks. But in my case, the workflow is triggered by issuing a comment. Will this still work? |
Beta Was this translation helpful? Give feedback.
-
Sure. When you add a comments on a PR, the issue_comment event is triggered. At this time, the issue_comment event is related to the PR. Tip: On GitHub, pull request is considered as a type of issue, that’s way some event types of PR will be combined as the common issue events. |
Beta Was this translation helpful? Give feedback.
-
Great! I’ll give it a go and report back 🙏 |
Beta Was this translation helpful? Give feedback.
-
@zachliu, |
Beta Was this translation helpful? Give feedback.
-
EDIT: When the workflow is triggered by the issue_comment event, the object will always be “github.event.issue”, so the author should be “github.event.issue.user.login”. To determine if it is a PR, you can see if the “github.event.issue.pull_request” object exists.
|
Beta Was this translation helpful? Give feedback.
-
It’s a bit confusing now. Let me tell the story again: |
Beta Was this translation helpful? Give feedback.
-
At this time, the workflow is triggered by pull_request event, to get the author who opened the PR, using the expression “github.event.pull_request.user.login”.
At this time, the workflow is triggered by issue_comment event, to get the author who opened the PR, using the expression “github.event.issue.user.login”. |
Beta Was this translation helpful? Give feedback.
-
Is it |
Beta Was this translation helpful? Give feedback.
-
No, I’m just saying the issue_comment event, not issues event. As I mentioned above, pull request is considered as a type of issue, but a PR is not exactly same with an issue.
Every time a workflow run is triggered, GitHub will generate the github context for this run. The github context contains many detailed information about the current workflow run, such as the repository name, the Git ref (branch, tag, commit SHA), the event that triggered the current run. In your case, the information you require can be get from the github context. In your workflow, you also can print the whole context of the github context to the logs and view more details.
The expressions “github.event.pull_request.user.login” and “github.event.issue.user.login” are used to get the values of the corresponding properties from the github context. |
Beta Was this translation helpful? Give feedback.
-
Great it works! Thank you! When B comments on A’s PR, I can use Now I am exploring |
Beta Was this translation helpful? Give feedback.
-
At this time, the event should be pull_request, and the activity type should be closed of the pull_request event. So, to get the the author of the PR, you need to use the expression “github.event.pull_request.user.login”.
Glad that the problems no longer bother you. |
Beta Was this translation helpful? Give feedback.
-
I have
but yeah, using |
Beta Was this translation helpful? Give feedback.
-
If you want the workflow is triggered when the PR is merged, yes, using pull_request + closed is good.
|
Beta Was this translation helpful? Give feedback.
-
Thank you so much! Since I’m commenting/closing my own PRs all night, I couldn’t really verify the solution 😅 . I’ll double check tmr morning and mark the solution then. Update: now I can confirm everything works fine. Thank you! @brightran |
Beta Was this translation helpful? Give feedback.
@zachliu,
At this time, the workflow is triggered by pull_request event, to get the author who opened the PR, using the expression “github.event.pull_request.user.login”.
The events “pull_request_review”, “pull_request_review_comment” and “pull_request_target” use the same expression.
At this time, the workflow is triggered by issue_comment event, to get the author who opened the PR, using the expression “github.event.issue.user.login”.