git-cliff
git-cliff copied to clipboard
Add committer/author data to the remote context
Is there an existing issue or pull request for this?
- [X] I have searched the existing issues and pull requests
Feature description
I am currently using a rather crude adhoc script to expand Github user names like @some-github-user-handle into "John Doe (@some-github-user-handle)". It would be nice if the Github backend could supply a remote.realname field next to remote.username.
Desired solution
Enrich the github remote record with remote.realname.
Alternatives considered
A post-processor that expands user names can come close, but having remote.realname available in the templates would be preferable. The post processor solution looks like this:
postprocessors = [
# '@some-github-user-handle' -> 'John Doe (@some-github-user-handle)'
{ pattern = '.*', replace_command = 'github-username-expander.py -' },
]
The script is attached as github-username-expander.py.txt, just remove the .txt and make it executable.
Additional context
No response
Thanks for opening your first issue at git-cliff! Be sure to follow the issue template! ⛰️
Hello 👋 thanks for reporting this!
Unfortunately GitHub API does not directly expose the realnames:
"author": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": false
},
But instead, you can probably use the committer or author data which belong to the commit object:
"commit": {
"url": "https://api.github.com/repos/octocat/Hello-World/git/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
"author": {
"name": "Monalisa Octocat",
"email": "[email protected]",
"date": "2011-04-14T16:00:49Z"
},
"committer": {
"name": "Monalisa Octocat",
"email": "[email protected]",
"date": "2011-04-14T16:00:49Z"
},
}
In git-cliff, this information is also exposed in the context (*) as commit.author or commit.committer. You can use it like this:
{{ commit.author.name }} (@{{ commit.remote.username }})
Orhun Parmaksız (@orhun)
I need the expansion for the contributor list, I don't think there is a commit available when you are looping over them right?
{% for contributor in github.contributors %}
* @{{ contributor.username }}
The script I am currently using queries the "name" through the Github API: github-username-expander.py.txt
Ah I see. In that case it is currently not possible to use the author or committer information.
Would making commit.author/commit.committer a part of the github object solve the issue for you?
Ah I see. In that case it is currently not possible to use the author or committer information.
Would making
commit.author/commit.committera part of thegithubobject solve the issue for you?
Not sure, is that usable per contributor? I.e. how could this template be adjusted:
{% for contributor in github.contributors %}
* @{{ contributor.username }}
Be adjusted to generate the Contributors list at the end of the following release notes?
https://github.com/tim-janik/jj-fzf/releases/tag/v0.23.0
Yeah, I'm thinking of making the following use case possible:
{% for contributor in github.contributors %}
* {{ contributor.author }} (@{{ contributor.username }})
I'm not sure about the naming though. What do you think?
Yeah, I'm thinking of making the following use case possible:
{% for contributor in github.contributors %} * {{ contributor.author }} (@{{ contributor.username }})I'm not sure about the naming though. What do you think?
Depends on the origin of the data. Is this going to be a Github only feature? If so, it'd make sense to stick to the Github names. E.g. looking at https://api.github.com/users/orhun there are several fields that could be of interest, e.g.:
* Current handle: {{ contributor.username }}
* Real name: {{ contributor.github.name }} (often null for organizations)
* Github handle: {{ contributor.github.login }} (same as contributor.username )
* Twitter handle: {{ contributor.github.twitter_username }}
If this is meant to work across remotes, it could be better to keep it more generic and then allow fallbacks.
E.g. if contributor.name was used, it could map to contributor.github.name iff that is available and non-null, but otherwise fall back to contributor.username.
Hmm, I'm actually thinking of just mapping the values from available remotes instead of sending separate requests for each one, e.g. this endpoint for GitHub. I'm not sure about the rest of the remotes.
I updated the title of the issue accordingly.