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

Conversation

na-ga
Copy link
Contributor

@na-ga na-ga commented Mar 29, 2022

Enabling the usePullRequestMetadata option of the releaseNoteGenerator is causing a behavior that limits Release Commits to Merge Commits.

However, we believe that this option should only affect Release Note generation. Therefore, we have modified the process to add metadata used for Release Note to Release Commit when this option is enabled.

In our use case we treat Release Commits as Metrics to be sent to FourKeys, so we need all the commits in the release.

@@ -273,22 +297,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.

release.go Outdated
if !commit.IsMerge() {
return nil, nil
}
if pr, ok := shaPRs[commit.Hash]; ok {
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 not a bugfix, but an improvement.

The subject of a merge commit may not match Merge pull request #([0-9]+) from .+ regex. So use merge commit SHA instead of PR Number to identify the PR.

Copy link
Member

Choose a reason for hiding this comment

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

Exactly, thank you for your improving.

if pr, ok := numPRs[prNumber]; ok {
return pr, 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
}
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.

release.go Outdated
if !commit.IsMerge() {
return nil, nil
}
if pr, ok := shaPRs[commit.Hash]; ok {
Copy link
Member

Choose a reason for hiding this comment

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

Exactly, thank you for your improving.

release.go Outdated
Comment on lines 266 to 272
prNumber, ok := commit.PullRequestNumber()
if !ok {
return nil, nil
}
if pr, ok := numPRs[prNumber]; ok {
return pr, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove this logic by above improvement?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! deleted on 8dde46a.

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

if gen.UsePullRequestMetadata {
prNumber, ok := commit.PullRequestNumber()
if !ok {
continue
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.

@knanao
Copy link
Member

knanao commented Mar 30, 2022

Thank you for your nice job!

if err != nil {
return nil, err
// only error logging, ignore error
log.Printf("Failed to get pull request: %v\n", err)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The PR Number retrieved from the commit subject is now the user's input value, so only logging is used when an error occurs. Commits that fall into this case are assumed to be output in the conventional form without PR metadata.

@nghialv
Copy link
Member

nghialv commented Mar 30, 2022

Thank you.
Let me merge this PR.

@nghialv nghialv merged commit 184e7fa into pipe-cd:main Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants