-
Notifications
You must be signed in to change notification settings - Fork 76
Comment specific preview links for changed files #1341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bmorelli25
wants to merge
15
commits into
main
Choose a base branch
from
bmorelli25-patch-2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
774d0a6
Create link-to-changed-files.yml
bmorelli25 e49784c
TEST
bmorelli25 17b3910
Ensure original message is edited when new changes happen
bmorelli25 f172ce7
Update and rename link-to-changed-files.yml to doc-preview-comment.yml
bmorelli25 e87c161
target correct workflow
bmorelli25 7020c33
Try running on deployment_status instead
bmorelli25 94a8c18
More deployment updates
bmorelli25 6686779
Update doc-preview-comment.yml
bmorelli25 c24380b
test snippet update
bmorelli25 c829e18
Merge branch 'bmorelli25-patch-2' of https://github.com/elastic/docs-…
bmorelli25 0745c3b
Revert "TEST"
bmorelli25 02d0756
Revert "test snippet update"
bmorelli25 7a9cc4c
Revert "Ensure original message is edited when new changes happen"
bmorelli25 651ce1b
fix the conflicts
bmorelli25 22a3222
clean
bmorelli25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,72 @@ | ||
name: "Docs preview comment" | ||
|
||
on: | ||
pull_request: | ||
types: [opened, reopened, synchronize] | ||
|
||
jobs: | ||
preview-links: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Comment preview links for changed docs | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const pr = context.payload.pull_request; | ||
const prNum = pr.number; | ||
const owner = context.repo.owner; | ||
const repo = context.repo.repo; | ||
const base = `https://docs-v3-preview.elastic.dev/${owner}/${repo}/pull/${prNum}`; | ||
|
||
// 1) List all files in this PR | ||
const { data: files } = await github.rest.pulls.listFiles({ | ||
owner, repo, pull_number: prNum | ||
}); | ||
|
||
// 2) Filter to only added/modified .md files (skip removed and _snippets/) | ||
const links = files | ||
.filter(f => | ||
f.status !== 'removed' && | ||
/\.md$/i.test(f.filename) && | ||
!/(^|\/)_snippets\//i.test(f.filename) | ||
) | ||
.map(f => { | ||
let p = f.filename.replace(/\/index\.md$/i, '/'); | ||
if (p === f.filename) p = p.replace(/\.md$/i, ''); | ||
return `- [\`${f.filename}\`](${base}/${p})`; | ||
}); | ||
|
||
if (!links.length) return; // nothing to do | ||
|
||
// 3) Build the comment body | ||
const body = [ | ||
"🔍 **Preview links for changed docs:**", | ||
"", | ||
...links, | ||
"", | ||
"🔔 *The preview site may take up to **5 minutes** to finish building. These links will become live once it completes.*" | ||
].join("\n"); | ||
|
||
// 4) Post or update a single bot comment | ||
const { data: comments } = await github.rest.issues.listComments({ | ||
owner, repo, issue_number: prNum | ||
}); | ||
const existing = comments.find(c => | ||
c.user.type === 'Bot' && | ||
c.body.startsWith("🔍 **Preview links for changed docs:**") | ||
); | ||
|
||
if (existing) { | ||
await github.rest.issues.updateComment({ | ||
owner, repo, | ||
comment_id: existing.id, | ||
body | ||
}); | ||
} else { | ||
await github.rest.issues.createComment({ | ||
owner, repo, | ||
issue_number: prNum, | ||
body | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5 minutes? 😢 https://github.com/elastic/docs-content/actions/workflows/docs-build.yml begs to differ!
Its a safe margin I get it 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just spotted the attempts to update on deployment created ❤️ that!
I think adding these permissions to the workflow would be sufficient.
https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#permissions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh snap! Thanks, I'll give this a try