'How to correctly set a Github App committer to show the app created the commit?

When using the GitHub Api you can supply the author and committer information, such as when you PUT a content file.

I want to be able to use the GitHub App as the committer so that people understand the commit was done using the third-party tool and the author information is kept as the authenticated user.

Currently I am using the app name as the name of the committer and an email for the apps' domain. But that does not tie the commit to the app at all (ex: I would have to create a bot account with that email to get it show any kind of profile, etc but that would not really be tied to my Github App).

What is the correct way to do this? Or should I not be trying to use the App as the committer and just use the authenticated user as the committer?



Solution 1:[1]

If you are confused as to how to get TOKEN from Marcel's example, as I was, here's a command that you can run from shell. You'll need your app id (numbers), app private key, and your repo name.

export APP_ID=123456
export APP_SECRET="$(cat app.private-key.pem)"
export GH_REPO=owner/repo
export TOKEN=$(bash get_github_app_token.sh)
curl -X PUT \
    -H "Authorization: token ${TOKEN}" \
    -H "Accept: application/vnd.github.v3+json" \
    https://api.github.com/repos/$GH_REPO/contents/test-file \
    -d '{"message":"message","content":"Y29udGVudA==","branch":"test"}'

This will create a commit on branch test. The branch must exist. The command will return a JSON that has wanted credentials. This needs open-ssl, jq, curl, and this neat script.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 squirrel