Got my account restored yesterday and I decided to write something interesting this morning.
Recently, some devs are obsessed with GitHub activity graphs(even some employers) , but this is totally absurd.
Why ?
Let’s write a script in 1hr or less….. #Thread #100DaysOfCode
Recently, some devs are obsessed with GitHub activity graphs(even some employers) , but this is totally absurd.
Why ?
Let’s write a script in 1hr or less….. #Thread #100DaysOfCode
First off, how does GitHub build the graph ?
A quick peek into the contribution graph shows that it’s purely based on commits.
If it’s built on commits, then shouldn’t we be able to write a simple script to commit on our behalf as a cron job while we sleep?
Ok, let’s go!
A quick peek into the contribution graph shows that it’s purely based on commits.
If it’s built on commits, then shouldn’t we be able to write a simple script to commit on our behalf as a cron job while we sleep?
Ok, let’s go!
A simple search here
https://www.slant.co/topics/1483/~best-scripting-languages-for-writing-shell-scripts
Shows bash, python , ruby and js as very good candidates for this.
Although any other language can implement this, python should be the best candidate as python is very easy to read.
https://www.slant.co/topics/1483/~best-scripting-languages-for-writing-shell-scripts
Shows bash, python , ruby and js as very good candidates for this.
Although any other language can implement this, python should be the best candidate as python is very easy to read.
First off, what’s the least work to be done ?
For each day :
1. Create a file
2. Make some changes to the file
3. Commit (as many as you prefer)
4. Push to GitHub
For each day :
1. Create a file
2. Make some changes to the file
3. Commit (as many as you prefer)
4. Push to GitHub
OK let's write an implementation for create_file.
we'll create a text file, write a commit_number and the date and time, then close the file.
we'll create a text file, write a commit_number and the date and time, then close the file.
To write an implementation for commit_changes, python’s “subprocess” will come in handy to execute our
“git add .” &&
“git commit" commands.
At this point we are technically done with our script.
“git add .” &&
“git commit" commands.
At this point we are technically done with our script.
Now let’s top it off with our push_changes function.
We’ll need only one line for this one :
“subprocess. run("git push -u origin master -f", check=True, shell=True)”
We’ll need only one line for this one :
“subprocess. run("git push -u origin master -f", check=True, shell=True)”
For each day :
we want to specify the number of commits as a variable, create a for-loop that runs create_file & commit_changes n times, then we finally push it with subprocess to a repo we create.
we want to specify the number of commits as a variable, create a for-loop that runs create_file & commit_changes n times, then we finally push it with subprocess to a repo we create.
Let’s create the repo then : https://github.com/RbkGh/gitconfreak
Now it’s time to test if all of that nonsense code makes sense and runs as expected.
Just add your Github ssh key to your local environment and add this script.
Just add your Github ssh key to your local environment and add this script.
Whew, success !
It committed .idea IDE folder in addition, who cares?!!
Now we can run 3 or 1000 commits per day if we wish!
Next, let’s wrap this in a cron job that runs everyday.
It committed .idea IDE folder in addition, who cares?!!
Now we can run 3 or 1000 commits per day if we wish!
Next, let’s wrap this in a cron job that runs everyday.
One google search and Python cron-tab comes to the rescue! https://pypi.org/project/python-crontab/
I’m hungry, let me go get something to eat.