-
Notifications
You must be signed in to change notification settings - Fork 284
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
Link to preview of latest commit in PR body #2287
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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,49 @@ | ||
name: Reusable PR Link Docs | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
CONCURRENCY: | ||
required: true | ||
type: string | ||
PR_NUMBER: | ||
required: true | ||
type: string | ||
|
||
concurrency: | ||
group: ${{ inputs.CONCURRENCY }}-pr-summary | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
pr-link-docs: | ||
name: Link to docs preview in PR | ||
|
||
permissions: | ||
contents: "read" | ||
id-token: "write" | ||
pull-requests: "write" | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.x | ||
|
||
- name: Install deps | ||
run: pip install PyGithub # NOLINT | ||
|
||
- name: Link to docs | ||
run: | | ||
python scripts/pr_link_docs.py \ | ||
--github-token ${{ secrets.GITHUB_TOKEN }} \ | ||
--github-repository ${GITHUB_REPOSITORY} \ | ||
--pr-number ${{ inputs.PR_NUMBER }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
PR_NUMBER: ${{ inputs.PR_NUMBER }} | ||
|
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,53 @@ | ||
#!/usr/bin/env python3 | ||
|
||
""" | ||
Script to generate a link to documentation preview in PRs. | ||
|
||
This is expected to be run by the `reusable_pr_link_docs.yml` GitHub workflow. | ||
|
||
Requires the following packages: | ||
pip install PyGithub # NOLINT | ||
""" | ||
|
||
import argparse | ||
|
||
from github import Github # NOLINT | ||
|
||
EMPTY_LINK = "<!-- This comment will be replaced by a link to the documentation preview -->" | ||
LINK_START = "<!-- pr-link-docs:start -->" | ||
LINK_END = "<!-- pr-link-docs:end -->" | ||
|
||
LINK_TEMPLATE = "<!-- pr-link-docs:start -->\nDocs preview: {{ link }}\n<!-- pr-link-docs:end -->" | ||
|
||
|
||
def main() -> None: | ||
parser = argparse.ArgumentParser(description="Generate a PR summary page") | ||
parser.add_argument("--github-token", required=True, help="GitHub token") | ||
parser.add_argument("--github-repository", required=True, help="GitHub repository") | ||
parser.add_argument("--pr-number", required=True, type=int, help="PR number") | ||
args = parser.parse_args() | ||
|
||
gh = Github(args.github_token) # NOLINT | ||
repo = gh.get_repo(args.github_repository) | ||
pr = repo.get_pull(args.pr_number) | ||
|
||
latest_commit = pr.get_commits().reversed[0] | ||
|
||
print(f"Latest commit: {latest_commit.sha}") | ||
|
||
link = LINK_TEMPLATE.replace("{{ link }}", f"https://rerun.io/preview/{latest_commit.sha[:7]}/docs") | ||
if EMPTY_LINK in pr.body: | ||
print("Empty link found, updating it") | ||
new_body = pr.body.replace(EMPTY_LINK, link) | ||
pr.edit(body=new_body) | ||
else: | ||
start = pr.body.find(LINK_START) | ||
end = pr.body.find(LINK_END) | ||
if start != -1 and end != -1: | ||
print("Existing link found, updating it") | ||
new_body = pr.body[:start] + link + pr.body[end + len(LINK_END) :] | ||
pr.edit(body=new_body) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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
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.
I think it is time to put ci-related scripts under
scripts/ci
to distinguish them from scripts meant for humans.Other candidates:
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.
(but perhaps in a follow-up PR)
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.
It's a small thing, but #2292 so we don't forget