A ruby script that uses the Github API to create a pull request and then commit it. Used for github page hosted sites
It's intended to be run as a cron job once per day. It will get the branches from a specified repository and merge the branch that matches a template (the default looks like "Scheduled(2017-10-10)"). If that branch is found, it will create a pull request and then merge that pull request into the master branch for the pages repository.
I've gotten tired to trying to manage my posting schedule.
One of the problems with github pages is that if you have it configured to ignore future posts then Github will not rebuild them when that time arrives.
I've seen posts on how to do make it so the pages show up using zapier, but they require two different zaps, require a google calendar connection and if you change the format of the date, a paid subscription to zapier.
That's too much for me to swallow just to get pages to show up when they should.
So, this script was born. It can be scheduled using cron once a day. It connects to github using today's date, checks to see if there is a matching branch and merges the branch into master if it's there.
Finally, the default name you should have for the branches should follow this format: Scheduled(2019-01-30)
This script requires ruby 2.4.0 to be installed along with with bundler gem.
-
Clone the repository to a location on the computer that will be running the job every day.
git clone https://github.com/digitalbias/blog_poster.git
-
Install the ruby gems for the project
bundle install
-
Rename
sample.env
to.env
-
Change the values in the new
.env
file.GITHUB_PASSWORD
can be either an oauth token or your password. You can changeBRANCH_NAME_TEMPLATE
to whatever you would like. Also if you don't like the default format of%Y-%m-%d
for the date, you can also update the date format.This makes it so you can have a completly different branch format the script looks at instead of
Scheduled(2017-10-10)
-
Change permissions on the
blog_poster.rb
file so it can be executed by your cron job. -
Set up cron job.
-
Schedule posts to your hearts content.