Skip to content
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

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/todo-auto-issues.yml
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 }')
Copy link
Member Author

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, since git diff marks added files with a plus in the output. Also, it removes all whitespaces after : and capitalizes a first non-whitespace character


# 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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: this is just a way of converting todo_list from string with newlines to an array so we could iterate over todos


# 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
Copy link
Member Author

Choose a reason for hiding this comment

The 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