-
Notifications
You must be signed in to change notification settings - Fork 608
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
dev-ux: create an issue for each TODO introduced in a merged PR #6636
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Check for TODOs | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
branches: | ||
- main | ||
|
||
jobs: | ||
scan-for-todos: | ||
runs-on: ubuntu-latest | ||
if: github.event.pull_request.merged == true | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
ref: ${{ github.event.pull_request.merge_commit_sha }} | ||
|
||
- name: Scan for TODOs | ||
id: todos | ||
run: | | ||
git fetch origin main | ||
todos=$(git diff ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.merge_commit_sha }} --unified=0 | awk '/^\+.*TODO:/ { sub(/^.*TODO:\s*/, ""); sub(/^ */, ""); $0=toupper(substr($0,1,1)) substr($0,2); print $0 }') | ||
|
||
# Set output | ||
echo "todo_list=$todos" >> $GITHUB_OUTPUT; | ||
|
||
- name: Create GitHub issue for each TODO | ||
if: steps.todos.outputs.todo_list != '' | ||
run: | | ||
# Split the `todo_list` string into an array | ||
SAVEIFS=$IFS # Save current IFS (Internal Field Separator) | ||
IFS=$'\n' # Change IFS to newline char | ||
todos=("${{ steps.todos.outputs.todo_list }}") # split the `todo_list` string into an array by the same name | ||
IFS=$SAVEIFS # Restore original IFS | ||
Comment on lines
+34
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: this is just a way of converting |
||
|
||
# Create an issue for each TODO | ||
for todo in "${todos[@]}"; do | ||
echo "Creating issue for TODO: $todo" | ||
curl -L \ | ||
-X POST \ | ||
-H "Accept: application/vnd.github+json" \ | ||
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
https://api.github.com/repos/${{ github.repository }}/issues \ | ||
-d '{"title":"'"$todo"'","body":"Auto-generated issue triggered by the merge of ${{ github.event.pull_request.html_url }} with an introduced TODO","assignees":["${{ github.event.pull_request.user.login }}"],"labels":["T:auto"]}' | ||
Comment on lines
+42
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: unfortunately it is not possible to use an existing github action for issue creation, since a PR can potentially introduce multiple TODOs. That is because we need to iterate over all of them, but as of my knowledge, if we used an existing action for opening an issue, we would have to iterate over a workflow's step, which is not currently possible |
||
done |
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.
note: this line greps "TODO:"-patterned lines from a diff introduced by a merged pull request. It does that by only checking lines starting with
+
sign, sincegit diff
marks added files with a plus in the output. Also, it removes all whitespaces after:
and capitalizes a first non-whitespace character