Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add committer/author data to the remote context #949

Open
1 task done
tim-janik opened this issue Nov 12, 2024 · 8 comments
Open
1 task done

Add committer/author data to the remote context #949

tim-janik opened this issue Nov 12, 2024 · 8 comments
Labels
feature/request New feature or request integration Related to remote integration

Comments

@tim-janik
Copy link

Is there an existing issue or pull request for this?

  • 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 tim-janik added the feature/request New feature or request label Nov 12, 2024
Copy link

welcome bot commented Nov 12, 2024

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

@orhun orhun removed their assignment Nov 12, 2024
@orhun orhun added the integration Related to remote integration label Nov 12, 2024
@orhun
Copy link
Owner

orhun commented Nov 12, 2024

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)

@tim-janik
Copy link
Author

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

@orhun
Copy link
Owner

orhun commented Nov 12, 2024

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?

@tim-janik
Copy link
Author

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

@orhun
Copy link
Owner

orhun commented Nov 13, 2024

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?

@tim-janik
Copy link
Author

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.

@orhun orhun changed the title Support expanded Github user names Add committer/author data to the remote context Nov 19, 2024
@orhun
Copy link
Owner

orhun commented Nov 19, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/request New feature or request integration Related to remote integration
Projects
None yet
Development

No branches or pull requests

2 participants