forked from Cpp2Rust/cpp2rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Trigger CI #3
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
Closed
Closed
Trigger CI #3
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b29742f
Suggest changes instead of automatically fixing them
lucic71 d3865b1
Intentionally break formatting
lucic71 8125d3d
Split auto-fixing in 2 workflows
lucic71 560875d
Fix paths
lucic71 2af5a44
Add write permissions
lucic71 4dc38f2
Try suggester in 2-workflows setup
lucic71 af04661
Fabricate a pull_request event for reviewdog
lucic71 ba1a56d
Overwrite the runner's event file with the PR event
lucic71 39cf8e5
Manually post suggestions
lucic71 3b5cb44
Revert "Intentionally break formatting"
lucic71 efe31ba
Trigger CI
lucic71 abf1ef2
Break formatting
lucic71 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,99 @@ | ||
| name: Format Apply | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: ["Format Check"] | ||
| types: [completed] | ||
|
|
||
| jobs: | ||
| suggest: | ||
| runs-on: ubuntu-latest | ||
| if: github.event.workflow_run.event == 'pull_request' | ||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
|
|
||
| steps: | ||
| - name: Download diff artifact | ||
| uses: actions/download-artifact@v4 | ||
| with: | ||
| name: format-diff | ||
| run-id: ${{ github.event.workflow_run.id }} | ||
| github-token: ${{ secrets.GITHUB_TOKEN }} | ||
| path: ${{ runner.temp }}/format-diff | ||
|
|
||
| - name: Read PR metadata | ||
| id: meta | ||
| run: | | ||
| echo "number=$(jq -r '.pull_request.number' ${{ runner.temp }}/format-diff/pr-event.json)" >> "$GITHUB_OUTPUT" | ||
| echo "sha=$(jq -r '.pull_request.head.sha' ${{ runner.temp }}/format-diff/pr-event.json)" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Post suggestion comments | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| DIFF_FILE: ${{ runner.temp }}/format-diff/format.diff | ||
| PR: ${{ steps.meta.outputs.number }} | ||
| REPO: ${{ github.repository }} | ||
| COMMIT: ${{ steps.meta.outputs.sha }} | ||
| run: | | ||
| python3 <<'PY' | ||
| import json, os, re, subprocess, sys | ||
|
|
||
| with open(os.environ["DIFF_FILE"]) as f: | ||
| lines = f.read().splitlines() | ||
|
|
||
| repo = os.environ["REPO"] | ||
| pr = os.environ["PR"] | ||
| commit = os.environ["COMMIT"] | ||
| endpoint = f"/repos/{repo}/pulls/{pr}/comments" | ||
|
|
||
| def post(comment): | ||
| r = subprocess.run( | ||
| ["gh", "api", endpoint, "-X", "POST", "--input", "-"], | ||
| input=json.dumps(comment), text=True, capture_output=True, | ||
| ) | ||
| if r.returncode != 0: | ||
| print(f"skip ({r.stderr.strip()})", file=sys.stderr) | ||
|
|
||
| path = None | ||
| i = 0 | ||
| posted = 0 | ||
| while i < len(lines): | ||
| line = lines[i] | ||
| if line.startswith("+++ b/"): | ||
| path = line[6:] | ||
| i += 1 | ||
| elif line.startswith("@@"): | ||
| m = re.match(r"@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@", line) | ||
| if not m: | ||
| i += 1; continue | ||
| old_start = int(m.group(1)) | ||
| old_count = int(m.group(2) or "1") | ||
| end_line = old_start + old_count - 1 | ||
| new_content = [] | ||
| i += 1 | ||
| while i < len(lines) and not lines[i].startswith("@@") and not lines[i].startswith("diff "): | ||
| l = lines[i] | ||
| if l.startswith("+") and not l.startswith("+++"): | ||
| new_content.append(l[1:]) | ||
| elif l.startswith(" "): | ||
| new_content.append(l[1:]) | ||
| i += 1 | ||
| body = "```suggestion\n" + "\n".join(new_content) + "\n```" | ||
| comment = { | ||
| "body": body, | ||
| "commit_id": commit, | ||
| "path": path, | ||
| "line": end_line, | ||
| "side": "RIGHT", | ||
| } | ||
| if end_line > old_start: | ||
| comment["start_line"] = old_start | ||
| comment["start_side"] = "RIGHT" | ||
| post(comment) | ||
| posted += 1 | ||
| else: | ||
| i += 1 | ||
|
|
||
| print(f"attempted {posted} suggestion comment(s)") | ||
| PY |
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
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
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.