{"id":406,"date":"2022-06-18T20:15:52","date_gmt":"2022-06-18T20:15:52","guid":{"rendered":"https:\/\/ootips.org\/yonat\/?p=406"},"modified":"2022-07-15T12:27:34","modified_gmt":"2022-07-15T12:27:34","slug":"add-pr-line-comment-from-github-actions","status":"publish","type":"post","link":"https:\/\/ootips.org\/yonat\/add-pr-line-comment-from-github-actions\/","title":{"rendered":"Add PR line comment from GitHub Actions"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2022\/06\/review-header-with-line-comment.png\"><img loading=\"lazy\" decoding=\"async\" width=\"674\" height=\"175\" src=\"https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2022\/06\/review-header-with-line-comment.png\" alt=\"\" class=\"wp-image-407\" srcset=\"https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2022\/06\/review-header-with-line-comment.png 674w, https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2022\/06\/review-header-with-line-comment-300x78.png 300w, https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2022\/06\/review-header-with-line-comment-500x130.png 500w\" sizes=\"auto, (max-width: 674px) 100vw, 674px\" \/><\/a><\/figure>\n\n\n\n<p>To have a pull request CI workflow that adds comments referring to specific lines of code, you don&#8217;t need any special action. Just use straight up bash:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\ngh api repos\/$GITHUB_REPOSITORY\/pulls\/${{ github.event.pull_request.number }}\/comments \\\n  -f body=&quot;$TEXT&quot; \\\n  -f path=&quot;$FILE_PATH&quot; \\\n  -F line=&quot;$LINE_NUMBER&quot; \\\n  -f side=&quot;RIGHT&quot; \\\n  -f commit_id=&quot;${{ github.event.pull_request.head.sha }}&quot;\n<\/pre><\/div>\n\n\n<p>Reference: <a rel=\"noreferrer noopener\" href=\"https:\/\/docs.github.com\/en\/rest\/pulls\/comments#create-a-review-comment-for-a-pull-request\" target=\"_blank\">GitHub REST API<\/a><\/p>\n\n\n\n<p>To pipe the output from another command to PR comments:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: bash; title: ; notranslate\" title=\"\">\nmy script outputting filepath + line + comment \\\n  | xargs -n 3 bash -c \\\n  &#039;gh api ...&#039;\n<\/pre><\/div>\n\n\n<p>And use <code>$0<\/code>, <code>$1<\/code>, <code>$2<\/code> for the file, line, and text arguments.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To have a pull request CI workflow that adds comments referring to specific lines of code, you don&#8217;t need any special action. Just use straight up bash: Reference: GitHub REST API To pipe the output from another command to PR &hellip; <a href=\"https:\/\/ootips.org\/yonat\/add-pr-line-comment-from-github-actions\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[1],"tags":[25,24],"class_list":["post-406","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-ci","tag-github"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2aEUP-6y","_links":{"self":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/406","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/comments?post=406"}],"version-history":[{"count":9,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/406\/revisions"}],"predecessor-version":[{"id":420,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/406\/revisions\/420"}],"wp:attachment":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/media?parent=406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/categories?post=406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/tags?post=406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}