Obliwonk - An automatic profile README updater

Jul 12, 2020

Obliwonk

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.

1type Provider interface {
2 GetContent() ([]byte, error)
3}

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

1type mathProvider struct {
2 url string
3}
4
5func NewMathProvider(config config.Config) Provider {
6 return &mathProvider{
7 url: config.MathProviderUrl,
8 }
9}
10
11func (m *mathProvider) GetContent() ([]byte, error) {
12 resp, err := http.Get(m.url)
13 if err != nil {
14 log.Println(err)
15 return nil, err
16 }
17 r, err := ioutil.ReadAll(resp.Body)
18 if err != nil {
19 return nil, err
20 }
21 return r, nil
22}

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

1OBLIWONK_GITHUB_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
2OBLIWONK_USERNAME=<github_username>
3OBLIWONK_README=README.md
4OBLIWONK_REPO_PRIVATE=true
5OBLIWONK_COMMIT_MESSAGE=Updated via Obliwonk
6OBLIWONK_MATH_PROVIDER_URL=http://numbersapi.com/random/math
7OBLIWONK_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.

1docker build . -t obliwonk:latest
20 */2 * * * docker run obliwonk:latest

You could also use GitHub Actions to schedule this workflow.

1name: Go
2
3on:
4 schedule:
5 - cron: 0 */2 * * *
6
7jobs:
8
9 build:
10 name: Build
11 runs-on: ubuntu-latest
12 steps:
13
14 - name: Set up Go 1.x
15 uses: actions/setup-go@v2
16 with:
17 go-version: ^1.13
18 id: go
19
20 - name: Check out code into the Go module directory
21 uses: actions/checkout@v2
22
23 - name: Get dependencies
24 run: |
25 go get -v -t -d ./...
26 if [ -f Gopkg.toml ]; then
27 curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
28 dep ensure
29 fi
30 - name: Build
31 run: go build
32
33 - name: Touch .env
34 run: touch .env
35
36 - name: Run obliwonk
37 env:
38 OBLIWONK_GITHUB_TOKEN: ${{ secrets.OBLIWONK_TOKEN }}
39 OBLIWONK_USERNAME: ${{ secrets.OBLIWONK_USERNAME }}
40 OBLIWONK_README: README.md
41 OBLIWONK_COMMIT_MESSAGE: ${{ secrets.OBLIWONK_COMMIT_MESSAGE }}
42 OBLIWONK_MATH_PROVIDER_URL: ${{ secrets.OBLIWONK_MATH_PROVIDER_URL }}
43 OBLIWONK_JOKE_PROVIDER_URL: ${{ secrets.OBLIWONK_JOKE_PROVIDER_URL }}
44 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

https://blog.trieoflogs.com/feed.xml