-
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 64eccb7
Showing
4 changed files
with
64 additions
and
69 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,46 @@ | ||
name: Update preview message | ||
description: Add a preview url to the existing preview comment, 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)) | ||
if (previewComment) { | ||
const hasPreviewUrl = body.includes(PREVIEW_URL) | ||
if (!hasPreviewUrl) { | ||
const body = previewComment.body | ||
.replace(commentInitialBody, '') | ||
.concat(`- ${PREVIEW_URL}\n`) | ||
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