Obliwonk - An automatic profile README updater
- HariharanObliwonk
Obliwonk is a slightly over-engineered profile README updater. Profile README is a really cool feature that allows you to add a README to your GitHub profile. It has already become a heavily used feature. To create one for yourself, you simply create a repository with your username as the repo name and add a README to it.
Now, it is fun to have a profile README, but having it self update would be even more fun. Obliwonk automates this and provides the notion of providers. Providers basically provide an abstraction over any content provider (for eg. APIs). Under the hood, a provider is just an implementation of the Provider interface.
type Provider interface {
GetContent() ([]byte, error)
}
Two providers are already included in the box, joke and math facts provider. As the names suggest, the joke provider provides jokes and math provider provides random facts about numbers. It goes without saying, you can create custom providers as well.
Sample provider
type mathProvider struct {
url string
}
func NewMathProvider(config config.Config) Provider {
return &mathProvider{
url: config.MathProviderUrl,
}
}
func (m *mathProvider) GetContent() ([]byte, error) {
resp, err := http.Get(m.url)
if err != nil {
log.Println(err)
return nil, err
}
r, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
return r, nil
}
This provider just fetches a random math fact from http://numbersapi.com/random/math
There is also a utility function to randomly choose a provider so everytime Obliwonk runs, the content is random from a random provider.
Sample Config
Add .env
to the project dir with the following env keys
OBLIWONK_GITHUB_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
OBLIWONK_USERNAME=<github_username>
OBLIWONK_README=README.md
OBLIWONK_REPO_PRIVATE=true
OBLIWONK_COMMIT_MESSAGE=Updated via Obliwonk
OBLIWONK_MATH_PROVIDER_URL=http://numbersapi.com/random/math
OBLIWONK_JOKE_PROVIDER_URL=https://official-joke-api.appspot.com/random_joke
Here the OBLIWONK_GITHUB_TOKEN
is a personal access token. It needs to have repo access enabled. The default math and joke providers use the corresponding URLs, these fields already have default values and are optional.
Instructions
You could use the included Dockerfile
to create a docker image and schedule it using a cron job.
docker build . -t obliwonk:latest
0 */2 * * * docker run obliwonk:latest
You could also use GitHub Actions to schedule this workflow.
name: Go
on:
schedule:
- cron: 0 */2 * * *
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.13
id: go
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Get dependencies
run: |
go get -v -t -d ./...
if [ -f Gopkg.toml ]; then
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
fi
- name: Build
run: go build
- name: Touch .env
run: touch .env
- name: Run obliwonk
env:
OBLIWONK_GITHUB_TOKEN: ${{ secrets.OBLIWONK_TOKEN }}
OBLIWONK_USERNAME: ${{ secrets.OBLIWONK_USERNAME }}
OBLIWONK_README: README.md
OBLIWONK_COMMIT_MESSAGE: ${{ secrets.OBLIWONK_COMMIT_MESSAGE }}
OBLIWONK_MATH_PROVIDER_URL: ${{ secrets.OBLIWONK_MATH_PROVIDER_URL }}
OBLIWONK_JOKE_PROVIDER_URL: ${{ secrets.OBLIWONK_JOKE_PROVIDER_URL }}
run: ./obliwonk
Create a file .github/workflows/go.yml
. You will also have to create the corresponding secrets. You would have to create a new personal access token and give it repo access instead of using the default workflows GitHub token.
Conclusion
This project is still a WIP. Some features that I would like to add include:
- Add support for templates
- Add more providers like GIF provider, News provider etc.
The project is hosted at https://github.com/cvhariharan/obliwonk