Skip to content

Commit

Permalink
add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Nov 18, 2022
1 parent 8e25091 commit 1851f80
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .github/actions/testcomment/comment.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

:x: **Pom.xml files are not well formatted !** [(more details)](###_URL_###})

Ensure your code build locally using:
```
mvn clean install
```
Or just validate pom formatting with :
```
mvn com.github.ekryd.sortpom:sortpom-maven-plugin:verify -PallPom
```
You can format pom.xml file with :
```
mvn com.github.ekryd.sortpom:sortpom-maven-plugin:sort -PallPom
```
38 changes: 38 additions & 0 deletions .github/actions/utils/addcomment/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: "Add Comment"
description: "Download comment content file, substitute some value, then add the comment on a PR"

inputs:
pullrequest_id:
description: 'Id of the pull request to which we want to add comment'
required: true
action_name:
description: 'The name of the "action" for which we want to create a comment'
required: true
job_url:
description: 'url of the concerned job'
required: true


runs:
using: "composite"
steps:

- name: Download Comment Template
uses: Bhacaz/checkout-files@v2
with:
files: .github/actions/${{inputs.action_name}}/comment.txt

- name: Substitute Value in Template
uses: bluwy/substitute-string-action@v1
id: sub
with:
_input-file: .github/actions/${{inputs.action_name}}/comment.txt
_format-key: '###_key_###'
URL: ${{inputs.job_url}}

- name: Add comment
uses: marocchino/sticky-pull-request-comment@adca94abcaf73c10466a71cc83ae561fd66d1a56
with:
number: ${{inputs.pullrequest_id}}
header: ${{inputs.action_name}}
message: ${{steps.sub.outputs.result}}
73 changes: 73 additions & 0 deletions .github/workflows/commentPR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Comment PR

on:
workflow_run:
workflows: ["Check PR"]
types:
- completed

env:
build_status_filename: "build_status"
pr_id_key: "pullrequestid"

jobs:
add_comment:
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request'
strategy:
matrix:
jobstep: [testcomment]

steps:
# Waiting https://github.com/actions/download-artifact/issues/172
# We are using github script
# Inspired by : https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
- name: Download Build Status File
uses: actions/[email protected]
with:
script: |
var artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == '${{env.build_status_filename}}'
})[0];
var download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
var fs = require('fs');
fs.writeFileSync('${{github.workspace}}/${{env.build_status_filename}}', Buffer.from(download.data));
- name: Read Status Build Status Properties File
id: read_property
uses: christian-draeger/[email protected]
with:
path: ${{env.build_status_filename}}
properties: ${{env.pr_id_key}} ${{ matrix.jobstep }}

- name: Download Add Comment Action
if: ${{ steps.read_property.outputs[matrix.jobstep] }} == 'success'
uses: Bhacaz/checkout-files@v2
with:
files: .github/actions/utils/addcomment/action.yml

- name: Add Comment
if: ${{ steps.read_property.outputs[matrix.jobstep] }} == 'success'
uses: ./.github/actions/utils/addcomment
with:
pullrequest_id: ${{ steps.read_property.outputs[env.pr_id_key]}}
action_name: ${{ matrix.jobstep }}
job_url: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}

- name: Delete Comment on Success
if: ${{ steps.read_property.outputs[matrix.jobstep]}} == 'failure'
uses: marocchino/sticky-pull-request-comment@adca94abcaf73c10466a71cc83ae561fd66d1a56
with:
number: ${{ steps.read_property.outputs.pullrequestid }}
header: ${{matrix.jobstep}}
delete: true

0 comments on commit 1851f80

Please sign in to comment.