DEV Community


Changed lines of code by language in GitHub pull request

Viacheslav Poturaev
Born in the snows of Siberia, wandering around the world, seeking for gold.
・2 min read

Keeping pull requests small is generally a good idea, and often checking the number of changed lines is the first step in code review.

Unfortunately, keeping the number of changed lines small is not always feasible. For a few lines of an actual program changes you may need to supply a large body of mocked data, generated code, documentation changes, tests and other resources.

For example you have received a PR for review.
alt text
Looks pretty big at glance.

A breakdown of changes into several groups may help to get a better understanding of the scope of the changes.

alt text

And then you can see that most of the changes in this PR are generated Go code, which may be reviewed with less caution.

Such a comment can be added to a PR using GitHub Action and a small tool built on top of an awesome scc.

name: cloc
    runs-on: ubuntu-latest
      - name: Checkout code
        uses: actions/checkout@v2
          path: pr
      - name: Checkout base code
        uses: actions/checkout@v2
          ref: ${{ github.event.pull_request.base.sha }}
          path: base
      - name: Count Lines Of Code
        id: loc
        run: |
          curl -OL && tar xf linux_amd64.tar.gz
          OUTPUT=$(cd pr && ../sccdiff -basedir ../base)
          echo "::set-output name=diff::$OUTPUT"

      - name: Comment Code Lines
        uses: marocchino/sticky-pull-request-comment@v2
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          header: LOC
          message: |
            ### Lines Of Code

            ${{ steps.loc.outputs.diff }}
Enter fullscreen mode Exit fullscreen mode

Discussion (0)