-
-
Notifications
You must be signed in to change notification settings - Fork 849
Use git history to find PRs in a tag instead of time #619
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
Use git history to find PRs in a tag instead of time #619
Conversation
Currently the two extra round-trip calls to the github api per PR are agonizingly slow. This should be revised to use the existing git history instead of github's api. What should GCG do for PRs that are "rebase and squash" PR merge strategies similar to how https://github.com/syl20bnr/spacemacs/ does it? I suspect that even using merged_at didn't work as no PRs are "merged" just closed and referenced in commit messages, so we can probably ignore that. |
Issues have no "merge" event so would have to continue to be time-based. I wonder what happens for issues that are opened and closed at points in the future? |
FYI I tried copy-pasting these file revisions into my local copy to try and fix things, and got two errors in succession:
and after fixing that one (just changing "tag" to "tag_sha")
|
@zyphlar Thanks! I am testing on a repo without diverged history, so I didn't notice the misnamed variable and haven't yet tested that error condition. For easier testing you can add my github fork to your git repo's remotes and check out the branch directly; no need to hand-copy changes. Also you can comment directly on the line of code in the files view instead of just in the comment thread making it easier to find the related line :). |
What do you expect to happen when there's diverged history? This is a giant
repo so maybe I can help test. This tool is only 90% useful to me while it
fails to pick up PRs when the merge is the same commit as the version...
…On Tue, Feb 13, 2018, 10:06 AM Hunter Haugen ***@***.***> wrote:
@zyphlar <https://github.com/zyphlar> Thanks! I am testing on a repo
without diverged history, so I didn't notice the misnamed variable and
haven't yet tested that error condition.
For easier testing you can add my github fork to your git repo's remotes
and check out the branch directly; no need to hand-copy changes. Also you
can comment directly on the line of code in the files view instead of just
in the comment thread making it easier to find the related line :).
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://github.com/skywinder/github-changelog-generator/pull/619#issuecomment-365352497>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC9MuQLlt_QTtKxwgtM-quMYbGpwT54ks5tUc8fgaJpZM4SAuF6>
.
|
6e925dc
to
c2fdf68
Compare
@zyphlar Perhaps the latest commit will fix the "merge commit is tagged" issue. And has the I still haven't handled divergent histories, which breaks how it used to work with time-based sorting, so that's coming. |
(Appreciating this line of research a lot, @hunner!) |
e59a372
to
c30d817
Compare
if issue["events"] && (event = issue["events"].find { |e| e["event"] == "merged" }) | ||
sha = event["commit_id"] | ||
|
||
sha_between_tags?(sha, newer_tag, older_tag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should now use the issue["first_occurring_tag"]
as it has already been fetched.
# @param newer_tag The tag to determine if sha is a member. | ||
# @param older_tag The tag prior to the newer tag. | ||
# @return [Boolean] Whether the sha exists in the newer/older tag comparison. | ||
def sha_between_tags?(sha, newer_tag, older_tag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer needed; info is available via add_first_occurring_tag_to_prs()
When running this on theforeman/puppet-pulp
I get warnings about being unable to fetch commits:
Oddly enough git show can find all commits. |
Cache invalidation allows them to be fetched, but I need to add ordering those commits by PR references. The actual "merge" commit doesn't show up for any cherry-picked commits by github's api: https://api.github.com/repos/theforeman/puppet-pulp/commits/c27e1eb vs https://api.github.com/repos/theforeman/puppet-pulp/commits/fb96de5 for https://api.github.com/repos/theforeman/puppet-pulp/pulls/282 and https://api.github.com/repos/theforeman/puppet-pulp/issues/282/events |
b7b61c4
to
bf07d37
Compare
This should also fix #497 |
And should fix #615 |
And should fix #560 |
80aeea9
to
007cb52
Compare
You're doing the work of our Holiness, the Flying Spaghetti Monster
himself! Thanks ❤️
…On Fri, Feb 16, 2018, 2:37 PM Hunter Haugen ***@***.***> wrote:
And should fix #560
<https://github.com/skywinder/github-changelog-generator/issues/560>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://github.com/skywinder/github-changelog-generator/pull/619#issuecomment-366378929>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC9Mn_HcVAp6FEm1GRQEsiboFMhp2G9ks5tVgMkgaJpZM4SAuF6>
.
|
A quick test on a reasonably complex repository tells me this would be much better than the current code. I'd still have some issues since we've cherry picked manually so there are now github PRs to refer to. This a fundamental problem and might need metadata in a config file since there is no API that could tell us that. |
This is ready-to-go. |
tl;dr: Me rubberducking to figure out what to do about PRs that have been rebased outside of github's api. Conclusion: I should add an option that checks comment events of a PR that matches The problem of rebased (traditional, or cherry-picked) merge commits not matching the API means that historically-included changes for existing changelogs would be removed from the changelog with no recourse other than to:
The first point isn't that bad but is annoying. The second point may be untenable to some projects. It would be nice to come up with some way to recognize rebased commits. How could we tell?
There are too many ambiguous criteria around detecting merged commits, so what other options do we have?
The first point would mean any rebased commits would be just as wrong as they were before without a way to fix it. Not great. The second option would solve rebased merged PRs, rebased "closed" PRs (do we want to?), cherry-picked PRs in multiple tags. Comments can be deleted or updated after merge/close to help adopting GCG for older PRs, and there can be multiple comments of this form indicating several tags in which the PR could be rebased for. The second option is susceptible to outside influences of malicious users comment-spamming closed PRs with random SHAs unrelated to the PR. Threads could be locked by admins, but this is unconventional and non-default. But the submitter of a PR can affect the title already, and only admins can apply labels. Authors of PRs may spam garbage PRs, close them, and then leave comments so maybe just admins should be recognized in the events. What about if admins are removed in the future? Comments are no longer by admins. I think we can live with that. |
0a59813
to
0ee5d45
Compare
When running with |
This is because the tag comparison generation is done purely by date ordering (as most of the GCG comparisons are before this change) and the fact that the tags are on divergent branches is not currently considered. A hash map of (branches => tags they contain) in addition to the array of time-ordered tags would be needed to resolve changelog diff comparison URLs in a realistic fashion. There isn't currently any place that needs this functionality (though it might have helped in my shas_in_tag comparison) so I'm probably not going to add it yet. |
Rebased onto #628 for lint. Where would docs for the rebase comment functionality go? I see https://github.com/skywinder/github-changelog-generator/wiki/Advanced-change-log-generation-examples but I'd rather have them in the codebase than on github's wiki if possible. |
The man page could have a section about that, with any amount of detail. That’s a Markdown document which we use ronn to create man pages etc from. |
man/git-generate-changelog.md
Outdated
@@ -203,6 +203,9 @@ Automatically generate changelog from your tags, issues, labels and pull request | |||
|
|||
Displays Help | |||
|
|||
## REBASED COMMITS | |||
|
|||
Github pull requests that have been merged whose merge commit SHA has been modified through rebasing, cherry picking, or some other method may be tracked via a special comment on Github. Git commit SHAs found in comments on pull requests matching the regular expression `/rebased commit: ([0-9a-f]{40})/i` will be used in place of the original merge SHA when being added to the changelog. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally tiny thing: Github
=> GitHub
is the on-brand spelling.
Ready for review again. @ekohl hopefully except for the tag comparison ordering this makes your changelogs generate more correctly. |
Fixes #580 |
@@ -164,6 +164,7 @@ def fetch_closed_pull_requests | |||
pull_requests = [] | |||
options = { state: "closed" } | |||
|
|||
# XXX Why does this override the base (HISTORY.md) setting? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually the options
hash to pass to the @client
not the @options
hash for gcg.
@olleolleolle Anything you'd like me to check into for the impacts of this change? Any other feedback before merging? |
print("Associating PRs with tags: #{i}/#{total}\r") if @options[:verbose] | ||
end | ||
else | ||
raise StandardError, "No merge sha found for PR #{pr['number']}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found a super-weird PR with regards to the github api: puppetlabs/puppetlabs-concat#2
As mentioned there, it has no events and no merge commit. This raises an error state in the current code that I didn't expect to ever trigger. Thanks github.
Fixes github-changelog-generator#617 Before this change PRs were associated with tags by the merge date of the PR, regardless of git branching history. In this change the oldest tag in which the merge commit of each PR occurs in is determined by using the Github compare API. That association is then used to sort PRs into their respective release. This change uses caching of commit history fetching and comparisons for speedup.
Unreleased PRs will be associated with the next release based on either the --release-branch or the GitHub default branch if a release branch is not specified PRs not found in tags or in the release branch (due to the SHAs changing during a rebase) may be associated with SHAs specified in GitHub comments.
These can be confused for methods or local variables without the @
@olleolleolle Rebased again. |
I’m leaning towards merging this and seeing any issues we can shake out on that side of the merge. The solution offered in this PR changes the unreleased version’s way of working - but it was wrong. |
Fixes #617