-
Notifications
You must be signed in to change notification settings - Fork 373
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Link to preview of latest commit in PR body (#2287)
<!-- Open the PR up as a draft until you feel it is ready for a proper review. Do not make PR:s from your own `main` branch, as that makes it difficult for reviewers to add their own fixes. Add any improvements to the branch as new commits to make it easier for reviewers to follow the progress. All commits will be squashed to a single commit once the PR is merged into `main`. Make sure you mention any issues that this PR closes in the description, as well as any other related issues. To get an auto-generated PR description you can put "copilot:summary" or "copilot:walkthrough" anywhere. --> ### What ### Checklist * [ ] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [ ] I've included a screenshot or gif (if applicable) <!-- This line will get updated when the PR build summary job finishes. --> PR Build Summary: https://build.rerun.io/pr/2287 <!-- pr-link-docs:start --> Docs preview: https://rerun.io/preview/49fbf30/docs <!-- pr-link-docs:end -->
- Loading branch information
Showing
5 changed files
with
113 additions
and
0 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,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