1

New Research Report - Exploring the 2024 State of Software Quality

Group 370
2

Codacy Product Showcase October 8th - Sign Up to Learn About Platform Updates

Group 370
3

Spotlight Whitepaper by IDC on Importance of Automated Code Review Technologies

Group 370

Using the API to add Codacy Grade details to the Readme

In this article:
Subscribe to our blog:

Some context

Prerequisites — A Placeholder

# An amazing repository with code<!-- codacy-status --> 
<!-- /codacy-status -->

Hands-on

name: Update Readmeon:
  push:
    branches-ignore:
      - masterjobs:
  update-readme:
    runs-on: ubuntu-latest
    steps:
     - uses: actions/checkout@v2
       with:
        ref: $
     - name: update README.md with codacy status
       run: |
          RETRIES=0
          ANALYZED=$(curl -X GET https://app.codacy.com/api/v3/analysis/organizations/gh/codacy-acme/repositories/nodeproject/commits/${GITHUB_SHA}/deltaStatistics -H 'api-token: $' | jq '.analyzed')
          while [ $ANALYZED != "true" ]
          do
          sleep 10s
          RETRIES=$((RETRIES+1))
          if [ "$RETRIES" -gt "10" ]; then
            echo "pipeline will exit due to max retries (10)"
            exit 0
          fi
          ANALYZED=$(curl -X GET https://app.codacy.com/api/v3/analysis/organizations/gh/codacy-acme/repositories/nodeproject/commits/${GITHUB_SHA}/deltaStatistics -H 'api-token: $' | jq '.analyzed')
          done
          RESULT=$(curl https://app.codacy.com/api/v3/analysis/organizations/gh/codacy-acme/repositories/nodeproject | jq -r -j '["Grade: \(.data.grade) |", "Issues: \(.data.issuesPercentage)% |", "Complex Files: \(.data.complexFilesPercentage)% |", "Coverage: \(.data.coverage.coveragePercentage)%"]' | tr -d \" | tr -d \[ | tr  -d \] | tr -d , | tr -d '\n')
          sed -i ":a;N;\$!ba;s/\(<!-- codacy-status -->\).*\(<!-- \/codacy-status -->\)/\1 \n$RESULT\n \2/g" README.md
       env:
        CI: true
     - uses: stefanzweifel/git-auto-commit-action@v4
       with:
        commit_message: "Update README.md with Project Grade"
        file_pattern: README.md

Downside

 

If you’d like to learn more about using the Codacy API, please check our docs page on the API v3. For more on our product and updates on our static analysis tool, check out Codacy’s product page.

This article was originally published by Hélio, Sr. Solutions Engineer at Codacy on his Medium account. 

RELATED
BLOG POSTS

New Pull Request Coverage Diff View Is Live
Developers often struggle to find and keep track of uncovered lines in their pull requests (PRs). Our latest feature, the Pull Request Coverage Diff...
Introducing Codacy Coverage: avoid breaking code by expanding unit tests
We are thrilled to launch our revamped product, Codacy Coverage. Taken from a product feature to a standalone solution, Codacy Coverage aims to help...
Showcasing Codacy at PyCon 2019
PyCon is an annual show in the U.S. that brings the Python community together for several days of talks, workshops, job fairs, and engagement...

Automate code
reviews on your commits and pull request

Group 13