Giter Club home page Giter Club logo

github-clone-count-badge's Introduction

Hey there

I'm a structural engineer who's also self-taught in programming. Besides my expertise in structural engineering, I specialize in Python automation.

  • ๐Ÿ”ญ Iโ€™m currently working on something cool ๐Ÿ˜‰
  • ๐ŸŒฑ Iโ€™m currently learning Python
  • ๐Ÿ“ซ How to reach me: MShawon's Email
  • โค๏ธ If you like my work and want to show some love: Donate

mshawon

github-clone-count-badge's People

Contributors

actions-user avatar mshawon avatar sekedus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

github-clone-count-badge's Issues

How to get the total views?

The workflow currently on this repo contains commands to extract and update the latest clone count.
How do I do the same for the total number of views?

Could you please possibly update the readme to reflect the code updating the view count?

Branch protection?

I am noticing while trying to use this workflow in my repo, that it essentially requires no branch protection rules in place. At first it gave me errors with my rule for requiring a review before pushing to main:
image

Upon disabling that and verified commits, I get an issue with pushes to main being required through a pull request:
image

Is there a way to use this workflow while keeping branch protection rules in place?

Error: Process completed with exit code 1.

I went through the whole documentation and also gave the permission which it been needed but still it gave me this error

Run git add .
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean
Error: Process completed with exit code 1.

image
image

Save clone count badge in comment

Just as an alternative, save clone count badge as a comment in gist:

name: GitHub Clone Count Update Everyday

on:
  schedule:
    # Runs at 12am UTC
    - cron: "0 0 * * *"
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      
      - name: gh login
        run: echo "${{ secrets.SECRET_TOKEN }}" | gh auth login --with-token

      - name: parse latest clone count
        run: |
          curl --user "${{ github.actor }}:${{ secrets.SECRET_TOKEN }}" \
            -H "Accept: application/vnd.github.v3+json" \
            https://api.github.com/repos/${{ github.repository }}/traffic/clones \
            > clone.json

      - name: create gist and download previous count
        id: set_id
        run: |
          if gh secret list | grep -q "GIST_ID"
          then
              echo "GIST_ID found"
              echo "GIST=${{ secrets.GIST_ID }}" >> $GITHUB_OUTPUT
              curl https://gist.githubusercontent.com/${{ github.actor }}/${{ secrets.GIST_ID }}/raw/clone.json > clone_before.json
              if cat clone_before.json | grep '404: Not Found'; then
                echo "GIST_ID not valid anymore. Creating another gist..."
                gist_id=$(gh gist create clone.json | awk -F / '{print $NF}')
                echo $gist_id | gh secret set GIST_ID
                echo "GIST=$gist_id" >> $GITHUB_OUTPUT
                cp clone.json clone_before.json
              fi
          else
              echo "GIST_ID not found. Creating a gist..."
              gist_id=$(gh gist create clone.json | awk -F / '{print $NF}')
              echo $gist_id | gh secret set GIST_ID
              echo "GIST=$gist_id" >> $GITHUB_OUTPUT
              cp clone.json clone_before.json
          fi

          if gh secret list | grep -q "GIST_COMMENT_ID"
          then
              echo "GIST_COMMENT_ID found"
              echo "COMMENT=${{ secrets.GIST_COMMENT_ID }}" >> $GITHUB_OUTPUT
              curl --user "${{ github.actor }}:${{ secrets.SECRET_TOKEN }}" \
              -H "Accept: application/vnd.github.v3+json" \
              https://api.github.com/gists/${{ secrets.GIST_ID }}/comments/${{ secrets.GIST_COMMENT_ID }} \
              > comment.json
              if cat comment.json | grep 'Not Found'; then
                echo "GIST_COMMENT_ID not found."
                echo "COMMENT=not_found" >> $GITHUB_OUTPUT
              fi
          else
              echo "GIST_COMMENT_ID not found."
              echo "COMMENT=not_found" >> $GITHUB_OUTPUT
          fi

      - name: update clone.json
        run: |
          curl https://raw.githubusercontent.com/MShawon/github-clone-count-badge/master/main.py > main.py
          python3 main.py

      - name: Update gist with latest count
        run: |
          if ! diff -q "clone.json" "clone_before.json" >/dev/null
          then
            content=$(sed -e 's/\\/\\\\/g' -e 's/\t/\\t/g' -e 's/\"/\\"/g' -e 's/\r//g' "clone.json" | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g')
            echo '{"description": "Clone statistics: ${{ github.repository }}", "files": {"clone.json": {"content": "'"$content"'"}}}' > post_clone.json
            curl -s -X PATCH \
              --user "${{ github.actor }}:${{ secrets.SECRET_TOKEN }}" \
              -H "Content-Type: application/json" \
              -d @post_clone.json https://api.github.com/gists/${{ steps.set_id.outputs.GIST }} > /dev/null 2>&1
            fi

      - name: Add badge comments
        run: |
          if [ "${{ steps.set_id.outputs.COMMENT }}" == "not_found" ]; then
            shields="https://img.shields.io/badge/dynamic/json?color=success&label=Clone&query=count&url="
            url="https://gist.githubusercontent.com/${{ github.actor }}/${{ steps.set_id.outputs.GIST }}/raw/clone.json"
            repo="https://github.com/MShawon/github-clone-count-badge"
            echo ''> BADGE.md
            echo '
            **Markdown**

            ```markdown' >> BADGE.md
            echo "[![GitHub Clones]($shields$url&logo=github)]($repo)" >> BADGE.md
            echo '
            ```

            **HTML**
            ```html' >> BADGE.md
            echo "<a href='$repo'><img alt='GitHub Clones' src='$shields$url&logo=github'></a>" >> BADGE.md
            echo '```' >> BADGE.md

            body=$(sed -e 's/\\/\\\\/g' -e 's/\t/\\t/g' -e 's/\"/\\"/g' -e 's/\r//g' "BADGE.md" | sed -E ':a;N;$!ba;s/\r{0,1}\n/\\n/g')
            echo '{"body": "'"$body"'"}' > post_comment.json
            comment_id=$(curl -s -X POST \
            --user "${{ github.actor }}:${{ secrets.SECRET_TOKEN }}" \
            -H "Content-Type: application/json" \
            -d @post_comment.json https://api.github.com/gists/${{ steps.set_id.outputs.GIST }}/comments \
            | jq '.id')
            echo $comment_id | gh secret set GIST_COMMENT_ID
          fi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.