Make a call to GitHub API from Workflow job #25226
-
Hello, I have a workflow that has 2 jobs. The first job runs angular tests and saves them to tests.log file. The second job just prints the content of the tests.log What I want however is to post the content of the tests.log file as a general comment on specific Pull Request. So,
I managed with 1-3 steps of my workflow. But for step 4 I don’t understand how to create a comment for a Pull Request; I managed to access and just read logs from tests.logs file. Search results for “GitHub API calls in workflow” and simmilar resulted in how to make API calls to get Workflow or Actions of a project. But I need an opposite thing - I need to call GitHub API inside a workflow |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
There’s actually an action that calls the Github API: https://github.com/octokit/request-action You can use that to create a comment something like:
It seems weird that I had to pass the pull request number as the issue number, and it may not be entirely correct, but it certainly worked when I tested it. Here’s the documentation on the API about comments on PRs (you’ve already read this I’m sure): https://developer.github.com/v3/pulls/comments/ |
Beta Was this translation helpful? Give feedback.
-
Hi @alishstrong , There is an action to add comment on PR, the comment content is from a file . If use GITHUB_TOKEN , the comment is added by github-actions bot . The file path need to be a relative path against .github/workflows . For example, your logs file is located in .github/workflows , then just specify the logs file name in finename variable. If the logs file is under the root path of your repo, you need to use …/…/tests.log . |
Beta Was this translation helpful? Give feedback.
-
This is the more correct solution. The API action is very versatile and exactly what I was looking for! |
Beta Was this translation helpful? Give feedback.
Hi @alishstrong ,
There is an action to add comment on PR, the comment content is from a file . If use GITHUB_TOKEN , the comment is added by github-actions bot .
The file path need to be a relative path against .github/workflows . For example, your logs file is located in .github/workflows , then just specify the logs file name in finename variable.
If the logs file is under the root path of your repo, you need to use …/…/tests.log .