Skip to content

Add last_committer_date and last_author_date for file contents API #32921

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

Merged
merged 1 commit into from
Apr 3, 2025

Conversation

lunny
Copy link
Member

@lunny lunny commented Dec 20, 2024

Fix #32886

Add last_committer_date and last_author_date in the content API which is not implemented by Github API v3 at the moment.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Dec 20, 2024
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels Dec 20, 2024
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Dec 20, 2024
@hiifong
Copy link
Member

hiifong commented Dec 24, 2024

ci test failed

@lunny lunny marked this pull request as draft December 25, 2024 05:13
@pull-request-size pull-request-size bot added size/L and removed size/M labels Dec 28, 2024
@lunny lunny marked this pull request as ready for review March 3, 2025 20:31
@lunny lunny added this to the 1.24.0 milestone Mar 3, 2025
@lunny lunny added the type/enhancement An improvement of existing functionality label Mar 3, 2025
@wxiaoguang
Copy link
Contributor

wxiaoguang commented Mar 4, 2025

GitHub API is like this https://docs.github.com/en/rest/commits/commits?apiVersion=2022-11-28#list-commits

    "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"
      },

Hmm, that's for commit, not for content .......

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Mar 4, 2025

I think this API is not right the request is not clear, "content time" is not the same as "commit time", actually there is no "content time" concept in git. There are 2 times: author time and commit time.

If I understand correctly:

  • author time: the content is generated by author
  • commit time: the time at which the commit is generated (could done by rebase or amend)

@lunny
Copy link
Member Author

lunny commented Mar 4, 2025

I think this API is not right the request is not clear, "content time" is not the same as "commit time", actually there is no "content time" concept in git. There are 2 times: author time and commit time.

If I understand correctly:

  • author time: the content is generated by author
  • commit time: the time at which the commit is generated (could done by rebase or amend)

The requirement is Add modified/created time to contents. For a file stored in the git, the lastest commit's author/commit time could be considered the modified time. The different between author time and commit time is commit could be rebase or amend so that commit time >= author time.

@wxiaoguang wxiaoguang marked this pull request as draft March 8, 2025 16:51
@wxiaoguang wxiaoguang force-pushed the lunny/add_last_commit_when branch 2 times, most recently from 475b482 to c5467d1 Compare April 3, 2025 02:39
@wxiaoguang wxiaoguang marked this pull request as ready for review April 3, 2025 02:39
@wxiaoguang wxiaoguang changed the title Add last commit when for contents API Add last committer and author time for contents API Apr 3, 2025
@wxiaoguang wxiaoguang force-pushed the lunny/add_last_commit_when branch 5 times, most recently from b46b083 to 11e07cf Compare April 3, 2025 03:20
@wxiaoguang wxiaoguang changed the title Add last committer and author time for contents API Add last committer and author date for contents API Apr 3, 2025
@wxiaoguang wxiaoguang force-pushed the lunny/add_last_commit_when branch from 11e07cf to 4502328 Compare April 3, 2025 03:26
@wxiaoguang wxiaoguang changed the title Add last committer and author date for contents API Add last_committer_date and last_author_date for file contents API Apr 3, 2025
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 3, 2025
@lunny lunny merged commit 45c4593 into go-gitea:main Apr 3, 2025
26 checks passed
@lunny lunny deleted the lunny/add_last_commit_when branch April 3, 2025 04:47
zjjhot added a commit to zjjhot/gitea that referenced this pull request Apr 8, 2025
* giteaofficial/main:
  [skip ci] Updated translations via Crowdin
  docs: add Chinese translations for README files (go-gitea#34132)
  Keep file tree view icons consistent with icon theme (go-gitea#33921)
  Make markdown render match GitHub's behavior (go-gitea#34129)
  Remove dead code: RepoRef (go-gitea#34131)
  Correctly handle submodule view and avoid throwing 500 error (go-gitea#34121)
  Use `overflow-wrap: anywhere` to replace `word-break: break-all` (go-gitea#34126)
  Fix markdown render behaviors (go-gitea#34122)
  Refactor dropdown ellipsis (go-gitea#34123)
  Avoid creating unnecessary temporary cat file sub process (go-gitea#33942)
  Fix discord webhook 400 status code when description limit is exceeded (go-gitea#34084)
  Refactor markup render to fix various path problems (go-gitea#34114)
  [skip ci] Updated translations via Crowdin
  Fix invalid version in RPM package path (go-gitea#34112)
  also check default ssh-cert location for host (go-gitea#34099) (go-gitea#34100)
  Fix markdown frontmatter rendering (go-gitea#34102)
  Get changed files based on merge base when checking `pull_request` actions trigger (go-gitea#34106)
  Add `last_committer_date` and `last_author_date` for file contents API (go-gitea#32921)
DennisRasey pushed a commit to DennisRasey/forgejo that referenced this pull request Apr 18, 2025
- Add a new field `last_commit_when` to the `ContentResponse` type, which is populated with the last commit's commiter date. This can be used to determine when the last edit of the content was.
- This field is compatible with what Gitea will likely add, go-gitea/gitea#32921. There's no field for this information in the Github API, so no way to be compatible with that (this API endpoint is otherwise fully compatible with Github's API).
- Ref: gitnex/GitNex#1225
- Integration test adjusted. The API tests cannot test the actual output, as `testify` tries to 'deep equal' the `time.Time` structs which will differ due how the `time.Time` struct is created. Unit tests still verify the output.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/7418
Reviewed-by: Earl Warren <[email protected]>
Co-authored-by: Gusted <[email protected]>
Co-committed-by: Gusted <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API] Add modified/created time to contents
5 participants