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

fix: behavior with usePullRequestMetadata option #26

Merged
merged 3 commits into from
Mar 30, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Copy link
Contributor Author

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.

if err != nil {
return nil, err
}
return pr, nil
}

out := make([]ReleaseCommit, 0, len(commits))
for _, commit := range commits {

Expand All @@ -273,22 +291,15 @@ func buildReleaseCommits(ctx context.Context, ghClient *githubClient, commits []
}

if gen.UsePullRequestMetadata {
prNumber, ok := commit.PullRequestNumber()
if !ok {
continue
Copy link
Contributor Author

@na-ga na-ga Mar 29, 2022

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got your point!
let's apply this improvement.

}
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 {
Copy link
Contributor Author

@na-ga na-ga Mar 29, 2022

Choose a reason for hiding this comment

The 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)
Expand Down