{"id":16556294,"url":"https://github.com/mshawon/github-clone-count-badge","last_synced_at":"2025-05-05T16:44:21.956Z","repository":{"id":65013650,"uuid":"334488354","full_name":"MShawon/github-clone-count-badge","owner":"MShawon","description":"GitHub clone count badge using shields.io","archived":false,"fork":false,"pushed_at":"2024-06-11T12:29:15.000Z","size":605,"stargazers_count":45,"open_issues_count":3,"forks_count":39,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-30T22:32:03.979Z","etag":null,"topics":["badge","clone","clone-count","github","github-actions","github-api","github-clone","shieldsio"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MShawon.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-30T18:54:53.000Z","updated_at":"2025-03-28T01:15:54.000Z","dependencies_parsed_at":"2024-10-27T11:12:19.148Z","dependency_job_id":"38a83a20-6069-48fd-8985-c6504e600d9f","html_url":"https://github.com/MShawon/github-clone-count-badge","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MShawon%2Fgithub-clone-count-badge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MShawon%2Fgithub-clone-count-badge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MShawon%2Fgithub-clone-count-badge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MShawon%2Fgithub-clone-count-badge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MShawon","download_url":"https://codeload.github.com/MShawon/github-clone-count-badge/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252535301,"owners_count":21763934,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["badge","clone","clone-count","github","github-actions","github-api","github-clone","shieldsio"],"created_at":"2024-10-11T20:04:05.798Z","updated_at":"2025-05-05T16:44:21.932Z","avatar_url":"https://github.com/MShawon.png","language":"Python","readme":"\u003cp align=\"center\"\u003e\n    \u003cimg alt=\"ViewCount\" src=\"https://views.whatilearened.today/views/github/MShawon/github-clone-count-badge.svg\"\u003e\n    \u003ca href='https://github.com/MShawon/github-clone-count-badge'\u003e\u003cimg alt='GitHub Clones' src='https://img.shields.io/badge/dynamic/json?color=success\u0026label=Clone\u0026query=count\u0026url=https://gist.githubusercontent.com/MShawon/cf89f3274d06170b8a4973039aa6220a/raw/clone.json\u0026logo=github'\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n# GitHub Clone Count Badge\n\nThis clone count badge shows **more than 14 days** of clone statistics of a GitHub repository.\n\n## How it works\n* Uses the following GitHub action to get repository clone count using `https://api.github.com/repos/{username}/{repo}/traffic/clones` this API. Then the **clone.json** file will be added to the user's https://gist.github.com/ account.\n* This action will run every 24th hours to update clone.json with the latest data. Unfortunately, GitHub API allows users to show only the last 14 day's clone data. But this badge will show all the statistics from the day you implement this action.\n* **clone.json** posted on https://gist.github.com/ will act as a database.\n* Then shields.io dynamic badge will parse this **clone.json** file to show the clone count.\n* Clone count badge is in **CLONE.md** file\n\n## Setup (~5 minute setup)\n1) [Create a new workflow](https://docs.github.com/en/actions/quickstart#creating-your-first-workflow) from the `Actions` tab of your repository. Name the file `clone.yml` and paste the following:\n```yaml\nname: GitHub Clone Count Update Everyday\n\non:\n  schedule:\n    - cron: \"0 */24 * * *\"\n  workflow_dispatch:\n\njobs:\n  build:\n    runs-on: ubuntu-latest\n\n    steps:\n      - uses: actions/checkout@v2\n      \n      - name: gh login\n        run: echo \"${{ secrets.SECRET_TOKEN }}\" | gh auth login --with-token\n\n      - name: parse latest clone count\n        run: |\n          curl --user \"${{ github.actor }}:${{ secrets.SECRET_TOKEN }}\" \\\n            -H \"Accept: application/vnd.github.v3+json\" \\\n            https://api.github.com/repos/${{ github.repository }}/traffic/clones \\\n            \u003e clone.json\n\n      - name: create gist and download previous count\n        id: set_id\n        run: |\n          if gh secret list | grep -q \"GIST_ID\"\n          then\n              echo \"GIST_ID found\"\n              echo \"GIST=${{ secrets.GIST_ID }}\" \u003e\u003e $GITHUB_OUTPUT\n              curl https://gist.githubusercontent.com/${{ github.actor }}/${{ secrets.GIST_ID }}/raw/clone.json \u003e clone_before.json\n              if cat clone_before.json | grep '404: Not Found'; then\n                echo \"GIST_ID not valid anymore. Creating another gist...\"\n                gist_id=$(gh gist create clone.json | awk -F / '{print $NF}')\n                echo $gist_id | gh secret set GIST_ID\n                echo \"GIST=$gist_id\" \u003e\u003e $GITHUB_OUTPUT\n                cp clone.json clone_before.json\n                git rm --ignore-unmatch  CLONE.md\n              fi\n          else\n              echo \"GIST_ID not found. Creating a gist...\"\n              gist_id=$(gh gist create clone.json | awk -F / '{print $NF}')\n              echo $gist_id | gh secret set GIST_ID\n              echo \"GIST=$gist_id\" \u003e\u003e $GITHUB_OUTPUT\n              cp clone.json clone_before.json\n          fi\n\n      - name: update clone.json\n        run: |\n          curl https://raw.githubusercontent.com/MShawon/github-clone-count-badge/master/main.py \u003e main.py\n          python3 main.py\n\n      - name: Update gist with latest count\n        run: |\n          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')\n          echo '{\"description\": \"${{ github.repository }} clone statistics\", \"files\": {\"clone.json\": {\"content\": \"'\"$content\"'\"}}}' \u003e post_clone.json\n          curl -s -X PATCH \\\n            --user \"${{ github.actor }}:${{ secrets.SECRET_TOKEN }}\" \\\n            -H \"Content-Type: application/json\" \\\n            -d @post_clone.json https://api.github.com/gists/${{ steps.set_id.outputs.GIST }} \u003e /dev/null 2\u003e\u00261\n\n          if [ ! -f CLONE.md ]; then\n            shields=\"https://img.shields.io/badge/dynamic/json?color=success\u0026label=Clone\u0026query=count\u0026url=\"\n            url=\"https://gist.githubusercontent.com/${{ github.actor }}/${{ steps.set_id.outputs.GIST }}/raw/clone.json\"\n            repo=\"https://github.com/MShawon/github-clone-count-badge\"\n            echo ''\u003e CLONE.md\n            echo '\n            **Markdown**\n\n            ```markdown' \u003e\u003e CLONE.md\n            echo \"[![GitHub Clones]($shields$url\u0026logo=github)]($repo)\" \u003e\u003e CLONE.md\n            echo '\n            ```\n\n            **HTML**\n            ```html' \u003e\u003e CLONE.md\n            echo \"\u003ca href='$repo'\u003e\u003cimg alt='GitHub Clones' src='$shields$url\u0026logo=github'\u003e\u003c/a\u003e\" \u003e\u003e CLONE.md\n            echo '```' \u003e\u003e CLONE.md\n            \n            git add CLONE.md\n            git config --global user.name \"GitHub Action\"\n            git config --global user.email \"action@github.com\"\n            git commit -m \"create clone count badge\"\n          fi\n\n      - name: Push\n        uses: ad-m/github-push-action@master\n        with:\n          github_token: ${{ secrets.GITHUB_TOKEN }}\n\n```\n2) But to use this, you will need a personal access token. See [this docs](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic) to get one. And make sure to select the following scopes:\n\n\u003cp align='center'\u003e\u003cimg src='scopes.png' width='90%'\u003e\u003c/p\u003e\n\n3) Next, add action secrets to this repository like [this docs](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions?tool=webui#creating-secrets-for-a-repository). Remember `SECRET_TOKEN` must be the secret name. And the value will be the **personal access token** you just generated.  \n\n\u003cp align='center'\u003e\u003cimg src='token.png' width='90%'\u003e\u003c/p\u003e\n\n4) Grant `Read and write permissions` to the workflow to add **CLONE.md** file to your repository. See [this docs](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository#configuring-the-default-github_token-permissions).\n\n\u003cp align='center'\u003e\u003cimg src='permissions.png' width='90%'\u003e\u003c/p\u003e\n\n## Badge Usage\n\nOnce you set it up correctly and the action is run for the very first time, the action will automatically create a new gist named **clone.json** in your account.\n\nBut you don't know the gist link yet that the shields.io badge needs to parse.\nSo a **CLONE.md** file will be uploaded to your repository's default branch which will contain the code required to add to your README.\n\n[action will create CLONE.md every time if not found]\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmshawon%2Fgithub-clone-count-badge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmshawon%2Fgithub-clone-count-badge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmshawon%2Fgithub-clone-count-badge/lists"}