git-cliff icon indicating copy to clipboard operation
git-cliff copied to clipboard

Add committer/author data to the remote context

Open tim-janik opened this issue 1 year ago • 8 comments

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

tim-janik avatar Nov 12 '24 03:11 tim-janik

Thanks for opening your first issue at git-cliff! Be sure to follow the issue template! ⛰️

welcome[bot] avatar Nov 12 '24 03:11 welcome[bot]

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)

orhun avatar Nov 12 '24 09:11 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

tim-janik avatar Nov 12 '24 12:11 tim-janik

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?

orhun avatar Nov 12 '24 20:11 orhun

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?

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

tim-janik avatar Nov 12 '24 20:11 tim-janik

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?

orhun avatar Nov 13 '24 10:11 orhun

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.

tim-janik avatar Nov 13 '24 13:11 tim-janik

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.

orhun avatar Nov 19 '24 16:11 orhun