-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2dc5d07
commit 1e25ba5
Showing
4 changed files
with
68 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Preview message creation | ||
description: Append a preview url message in the pr body, if not already present | ||
|
||
inputs: | ||
access-token: | ||
description: The access token to use for commenting. | ||
required: true | ||
preview-url: | ||
description: The preview url to add in the comment. | ||
required: true | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- uses: actions/github-script@v7 | ||
env: | ||
PREVIEW_URL: ${{ inputs.preview-url }} | ||
with: | ||
github-token: ${{ inputs.access-token }} | ||
script: | | ||
const commentTitle = '**Related Previews**' | ||
const commentInitialBody = 'Preview URLs will be added here, once they are ready... ![loader](https://github.com/swisspost/design-system/assets/9716662/49a75898-7093-4ffb-9460-071ff194459d)' | ||
const credentials = { | ||
repo: context.repo.repo, | ||
owner: context.repo.owner, | ||
issue_number: context.issue.number | ||
} | ||
const comments = (await github.rest.issues.listComments({ ...credentials })).data || [] | ||
const previewComment = comments.find(c => c.user.login === 'swisspost-bot' && c.body.includes(commentTitle)) | ||
console.log('---------------') | ||
console.log(previewComment?.body || 'previewComment not found') | ||
if (previewComment) { | ||
console.log('---------------') | ||
console.log(previewComment.body) | ||
const containsPreviewUrl = body.includes(PREVIEW_URL) | ||
if (!containsPreviewUrl) { | ||
const body = previewComment.body | ||
.replace(commentInitialBody, '') | ||
.concat(`- ${PREVIEW_URL}\n`) | ||
console.log(body) | ||
github.rest.issues.updateComment({ | ||
...credentials, | ||
body: body | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters