├── LICENSE ├── README.md └── activity.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 DevDojo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitHub Activity Demo Script 2 | 3 | This script aims to prove why you should not be too quick at judging people by their GitHub activity stats. 4 | 5 | The script will turn your contributions graph from this: 6 | 7 | ![GitHub Activity Before](https://imgur.com/SFQ3RJz.png) 8 | 9 | Into this: 10 | 11 | ![GitHub Activity After](https://imgur.com/xJ6MjFH.png) 12 | 13 | In 20-30 seconds. 14 | 15 | > Use for demo purposes only! 16 | 17 | To execute just run the following commaind inside a demo repository: 18 | 19 | 1. First download the script 20 | 2. After that run the script 21 | 3. Finally, push your changes to GitHub 22 | 23 | # Get started 24 | 25 | ```bash 26 | ACTIVITY_BR=main && MAX_PAST_DAYS=365 && COMMIT_NB= && COMMIT_MAX=7 && \ 27 | curl -sL 'https://raw.githubusercontent.com/bobbyiliev/github-activity-bash-script/main/activity.sh' \ 28 | | bash ; 29 | ``` 30 | 31 | # Environment variables 32 | 33 | | env | description | type | default value | 34 | |:-------------------:|:---------------------:|:-------------:|:------------------------------:| 35 | | `ACTIVITY_BR` | working git branch | `string` | `main` | 36 | | `MAX_PAST_DAYS` | number of past days | `integer` | `365` | 37 | | `COMMIT_NB` | exactly git commit number each past day. | `integer` | | 38 | | `COMMIT_MAX` | randomly git commit number each past day between [1..max] | `integer` | `7` | 39 | 40 | * `COMMIT_MAX` used only if `COMMIT_NB` is empty 41 | * if both `COMMIT_MAX` and `COMMIT_NB`, randomly commit number each past day between [1..7] 42 | 43 | # Introduction to Bash Scripting 44 | 45 | In case that you are interested in learning more about Bash Scripting, make sure to checkout this open-source eBook: 46 | 47 | **[Introduction to Bash Scripting](https://github.com/bobbyiliev/introduction-to-bash-scripting)** 48 | 49 | # Blog Post 50 | 51 | [Here is why you should not be too quick at judging people by their GitHub activity stats](https://devdojo.com/bobbyiliev/here-is-why-you-should-not-be-too-quick-at-judging-people-by-their-github-activity-stats?ref=bobbyiliev) 52 | -------------------------------------------------------------------------------- /activity.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # 6 | ## Use for demo purposes only! 7 | ## To execute just run the following commaind inside a demo repository: 8 | # 9 | # wget https://raw.githubusercontent.com/bobbyiliev/github-activity-bash-script/main/activity.sh 10 | # bash activity.sh 11 | # 12 | ## Finllly push your changes to GitHub: 13 | # 14 | # git push origin -f your_branch_name" 15 | # 16 | 17 | if [[ ! -d ".git" ]] ; then 18 | cwd=$(pwd) 19 | dir=$(mktemp -d -p $cwd test-git-repo-XXXXXXXXX) 20 | mkdir -p $dir 21 | cd $dir 22 | git init 23 | >&2 echo NO. NOT git repo... 24 | exit 1 25 | fi 26 | 27 | # thomas-nyman CC BY-SA 3.0 https://unix.stackexchange.com/a/155077 28 | if [[ -z "$(git status --porcelain)" ]] ; then 29 | echo OK. Working directory clean... 30 | else 31 | >&2 echo NO. Working directory NOT clean. Uncommitted changes... 32 | exit 2 33 | fi 34 | 35 | if [[ -z "ACTIVITY_BR" ]] ; then 36 | ACTIVITY_BR="main" 37 | fi 38 | git checkout --orphan $ACTIVITY_BR >/dev/null 2>&1 || git checkout $ACTIVITY_BR > /dev/null 2>&1 39 | 40 | # Create temp commits direcotry 41 | if [[ ! -d .commits ]] ; then 42 | mkdir -p .commits 43 | fi 44 | 45 | # Add changes file log 46 | if [[ ! -f .commits/changes ]] ; then 47 | touch .commits/changes 48 | fi 49 | 50 | if [[ -z "$MAX_PAST_DAYS" ]] ; then 51 | MAX_PAST_DAYS=365 52 | fi 53 | 54 | # Create commits for the past 365 days 55 | for (( day=$MAX_PAST_DAYS; day>=1; day-- )) ; do 56 | # Get the past date of the commit 57 | day2=$(date --date="-${day} day" "+%a, %d %b %Y %X %z") 58 | 59 | echo "Creating commits for ${day}" 60 | 61 | # Generate random number of commits for that date 62 | if [[ -z "$COMMIT_NB" ]] ; then 63 | if [[ -z "$COMMIT_MAX" ]] ; then 64 | commits=$(( ( RANDOM % 6 ) + 2 )) 65 | else 66 | commits=$(( ( RANDOM % $COMMIT_MAX ) + 1 )) 67 | fi 68 | else 69 | commits=$COMMIT_NB 70 | fi 71 | 72 | # Create the comits 73 | echo "Creating ${commits} commits" 74 | for ((i=1;i<=${commits};i++)); do 75 | content=$(date -d "${day2}" +"%s") 76 | echo ${content}-${i} >> .commits/changes 77 | git add .commits/changes 78 | git commit -m "Commit number ${content}-${i}" 79 | git commit --amend --no-edit --date "${day2}" 80 | done 81 | done 82 | 83 | function yes_or_no { 84 | # author : tiago-lopo john-kugelman CC BY-SA 3.0 https://stackoverflow.com/a/29436423 85 | # usage : yes_or_no "$message" && do_something 86 | # modified 87 | while true; do 88 | read -p "$* [y/n]: " yn 89 | case $yn in 90 | [YyOo]*) return 0 ;; 91 | [Nn]*) echo "Aborted" ; return 1 ;; 92 | esac 93 | done 94 | } 95 | 96 | if command -v gh ; then 97 | echo 98 | echo OK. github cli found. 99 | yes_or_no "Did you want to create repo on github ? " && \ 100 | gh repo create $(basename $(pwd)) \ 101 | -y \ 102 | --private \ 103 | --description 'generated by https://github.com/ccdd12/github-activity-bash-script' \ 104 | --homepage 'https://github.com/ccdd12/github-activity-bash-script' \ 105 | >/dev/null 2>&1 || \ 106 | echo NO. repo already exist. 107 | fi 108 | 109 | echo 110 | yes_or_no "Did you want to push to remote 'origin' ? " && \ 111 | git push --force --set-upstream origin $ACTIVITY_BR || \ 112 | echo OK. push to your own remote remote/branch. 113 | 114 | cat << EOF 115 | 116 | 117 | 118 | Generating commits completed... 119 | 120 | To push your changes later : 121 | 122 | git remote add origin https://github.com/username/$(basename $(pwd)) 123 | 124 | gh repo create 125 | git push --force --set-upstream origin $ACTIVITY_BR 126 | 127 | 128 | EOF 129 | --------------------------------------------------------------------------------