-
Notifications
You must be signed in to change notification settings - Fork 6
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
fix: behavior with usePullRequestMetadata option #26
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -235,7 +235,7 @@ func buildReleaseCommits(ctx context.Context, ghClient *githubClient, commits [] | |
} | ||
|
||
gen, limit := cfg.ReleaseNoteGenerator, 1000 | ||
prs := make(map[int]*github.PullRequest, limit) | ||
prs := make(map[string]*github.PullRequest, limit) | ||
if gen.UsePullRequestMetadata { | ||
opts := &ListPullRequestOptions{ | ||
State: PullRequestStateClosed, | ||
|
@@ -248,11 +248,29 @@ func buildReleaseCommits(ctx context.Context, ghClient *githubClient, commits [] | |
return nil, err | ||
} | ||
for i := range v { | ||
number := *v[i].Number | ||
prs[number] = v[i] | ||
sha := *v[i].MergeCommitSHA | ||
prs[sha] = v[i] | ||
} | ||
} | ||
|
||
getPullRequest := func(commit Commit) (*github.PullRequest, error) { | ||
if !commit.IsMerge() { | ||
return nil, nil | ||
} | ||
if pr, ok := prs[commit.Hash]; ok { | ||
return pr, nil | ||
} | ||
prNumber, ok := commit.PullRequestNumber() | ||
if !ok { | ||
return nil, nil | ||
} | ||
pr, err := ghClient.getPullRequest(ctx, event.Owner, event.Repo, prNumber) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return pr, nil | ||
} | ||
|
||
out := make([]ReleaseCommit, 0, len(commits)) | ||
for _, commit := range commits { | ||
|
||
|
@@ -273,22 +291,15 @@ func buildReleaseCommits(ctx context.Context, ghClient *githubClient, commits [] | |
} | ||
|
||
if gen.UsePullRequestMetadata { | ||
prNumber, ok := commit.PullRequestNumber() | ||
if !ok { | ||
continue | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where the behavior of excluding commits for which the PR Number cannot be obtained occurs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got your point! |
||
} | ||
c.PullRequestNumber = prNumber | ||
|
||
var err error | ||
pr, ok := prs[prNumber] | ||
if !ok { | ||
pr, err = ghClient.getPullRequest(ctx, event.Owner, event.Repo, prNumber) | ||
} | ||
pr, err := getPullRequest(commit) | ||
if err != nil { | ||
return nil, err | ||
} | ||
c.PullRequestOwner = pr.GetUser().GetLogin() | ||
c.ReleaseNote = extractReleaseNote(pr.GetTitle(), pr.GetBody(), gen.UseReleaseNoteBlock) | ||
if pr != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ReleaseNote and PR Metadata are added only when a PR is obtained. In other words, even if a PR cannot be obtained, it will be included in the Release Commit list. |
||
c.PullRequestNumber = pr.GetNumber() | ||
c.PullRequestOwner = pr.GetUser().GetLogin() | ||
c.ReleaseNote = extractReleaseNote(pr.GetTitle(), pr.GetBody(), gen.UseReleaseNoteBlock) | ||
} | ||
} | ||
|
||
out = append(out, c) | ||
|
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.
If the PR is not retrieved on the first fetch, the API will be called as usual using the PR Number.