forked from PickNikRobotics/moveit_pro_empty_ws
-
Notifications
You must be signed in to change notification settings - Fork 10
Add overlap-warning workflow for files shared with moveit_pro_empty_ws #635
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
JWhitleyWork
wants to merge
1
commit into
main
Choose a base branch
from
add-empty-ws-overlap-warning
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.
+72
−0
Open
Changes from all commits
Commits
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: Warn on moveit_pro_empty_ws overlap | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| overlap: | ||
| name: Check overlap with moveit_pro_empty_ws | ||
| runs-on: ubuntu-22.04 | ||
| steps: | ||
| - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 | ||
| with: | ||
| script: | | ||
| const upstream = { owner: 'PickNikRobotics', repo: 'moveit_pro_empty_ws', ref: 'main' }; | ||
| const marker = '<!-- empty-ws-overlap-warning -->'; | ||
|
|
||
| const changed = await github.paginate( | ||
| github.rest.pulls.listFiles, | ||
| { owner: context.repo.owner, repo: context.repo.repo, pull_number: context.issue.number, per_page: 100 }, | ||
| (res) => res.data.filter((f) => f.status !== 'removed').map((f) => f.filename), | ||
| ); | ||
|
|
||
| const branch = await github.rest.repos.getBranch({ owner: upstream.owner, repo: upstream.repo, branch: upstream.ref }); | ||
| const tree = await github.rest.git.getTree({ | ||
| owner: upstream.owner, | ||
| repo: upstream.repo, | ||
| tree_sha: branch.data.commit.commit.tree.sha, | ||
| recursive: 'true', | ||
| }); | ||
| if (tree.data.truncated) { | ||
| core.warning(`Tree for ${upstream.owner}/${upstream.repo}@${upstream.ref} was truncated; overlap result may be incomplete.`); | ||
| } | ||
| const upstreamPaths = new Set(tree.data.tree.filter((e) => e.type === 'blob').map((e) => e.path)); | ||
| const overlap = changed.filter((p) => upstreamPaths.has(p)).sort(); | ||
|
|
||
| const existing = await github.paginate(github.rest.issues.listComments, { | ||
| owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, per_page: 100, | ||
| }); | ||
| const prior = existing.find((c) => c.body && c.body.includes(marker)); | ||
|
|
||
| if (overlap.length === 0) { | ||
| if (prior) { | ||
| await github.rest.issues.deleteComment({ owner: context.repo.owner, repo: context.repo.repo, comment_id: prior.id }); | ||
| } | ||
| core.info('No overlap with moveit_pro_empty_ws.'); | ||
| return; | ||
| } | ||
|
|
||
| const body = [ | ||
| marker, | ||
| `⚠️ This PR modifies ${overlap.length} file(s) that also exist in [\`${upstream.owner}/${upstream.repo}\`](https://github.com/${upstream.owner}/${upstream.repo}/tree/${upstream.ref}).`, | ||
| '', | ||
| 'Consider whether the change should land upstream in `moveit_pro_empty_ws` first so downstream forks pick it up on the next sync.', | ||
| '', | ||
| '<details><summary>Overlapping files</summary>', | ||
| '', | ||
| ...overlap.map((p) => `- \`${p}\``), | ||
| '', | ||
| '</details>', | ||
| ].join('\n'); | ||
|
|
||
| if (prior) { | ||
| await github.rest.issues.updateComment({ owner: context.repo.owner, repo: context.repo.repo, comment_id: prior.id, body }); | ||
| } else { | ||
| await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, body }); | ||
| } | ||
| core.warning(`Overlap with ${upstream.owner}/${upstream.repo}: ${overlap.length} file(s).`); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.