Track GitHub Issue Checklist Progress Using 1 Simple Script

Vlad OsmianskiVlad Osmianski
2 min read

Until recently, GitHub issues had a handy indicator showing how many check list items are inside, and how many of them are checked.

Not anymore. It’s gone.

If it bothers you, stay with me, this article is how to compensate it.

The solution is to create a GitHub action that would add the check list summary to the issue title.

Here is a step-by-step guide:

  1. Create the .github/workflows/update-progress.yml file in your repository with the following contents. Due the location of the file and the on: section, GitHub executes the script written in the script: section any time you open or edit an issue. The script logic is simple - it read the issue, counts the completed/total check items in the body and adds these counts to the end of the issue title, or updates them if it’s not the first time:

     name: Update Project Progress
    
     on:
       issues:
         types: [edited, opened]
    
     jobs:
       update-progress:
         runs-on: ubuntu-latest
         steps:
           - name: Update project progress
             uses: actions/github-script@v7
             with:
               github-token: "${{ secrets.PAT_TOKEN }}"
               script: |
                 const {repository} = await github.graphql(`
                     query {
                         repository(owner: "${context.repo.owner}", name: "${context.repo.repo}") {
                             issue(number: ${context.issue.number}) {
                                 id
                                 title
                                 body
                             }
                         }
                     }
                 `);
    
                 const body = repository.issue.body;
                 const totalItems = (body.match(/- \[([ x])\]/g) || []).length;
                 const completedItems = (body.match(/- \[x\]/g) || []).length;
                 const progress = totalItems ? ` [${completedItems} / ${totalItems}]` : '';
    
                 // Remove existing progress count if present and add new one
                 const title = repository.issue.title.replace(/\s*\[\d+\s*\/\s*\d+\]$/, '') + progress;
    
                 if (title === repository.issue.title) {
                     return;
                 }
    
                 await github.graphql(`
                     mutation {
                         updateIssue(input: {
                             id: "${repository.issue.id}"
                             title: "${title}"
                         }) {
                             issue {
                                 id
                                 title
                             }
                         }
                     }
                 `);
    
  2. The github-token: "${{ secrets.PAT_TOKEN }}" line in the file tells GitHub under the name of which user to perform the action. Let’s say it’s you 😀Then, perform the next two steps to specify that.

  3. Click on your avatar in the right top corner, and go to SettingsDeveloper settingsPersonal access tokensTokens (classic). There, click Generate new tokenGenerate new token (classic), and fill in the form making sure you select repo (Full control of private repositories). Copy the generated token(it should start with ghp_…) to the clipboard.

  4. In your repository, go to SettingsSecuritySecrets and variablesActions, click the New repository secret, name it PAT_TOKEN, paste the token that you copied in the previous step, and save.

That’s it.

Now, create an issue with a check list item in it, wait a little and see that check list stats apeared in the title.

Enjoy!

0
Subscribe to my newsletter

Read articles from Vlad Osmianski directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Vlad Osmianski
Vlad Osmianski

A senior PHP + JavaScript + MySql developer of large-scale websites & backends and entrepreneur living in Vilnius, Lithuania with my wife Monika and my parrot Johnny. Very good at project management and communication, too. I’m here to create stuff that is useful to other people. Let's keep in touch!