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

Update pr/issue field in fragment/changelog to store the URL #95

Merged
merged 8 commits into from
Sep 20, 2022

Conversation

lucian-ioan
Copy link
Collaborator

@lucian-ioan lucian-ioan commented Sep 12, 2022

Closes #89

  • remove current fragments/changelog
  • add fragment
  • remove repository field
  • fix script for Windows

@elasticmachine
Copy link
Collaborator

elasticmachine commented Sep 12, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-09-20T14:22:29.996+0000

  • Duration: 3 min 47 sec

Test stats 🧪

Test Results
Failed 0
Passed 71
Skipped 0
Total 71

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@endorama endorama added this to the v0.3.0 milestone Sep 12, 2022
@endorama
Copy link
Member

endorama commented Sep 12, 2022

Please also remove the repository field from Fragment/Entry (and the tools script)

@@ -134,7 +135,13 @@ func (b Builder) Build(owner, repo string) error {
}

b.changelog.Entries[i].LinkedIssue = linkedIssues
} else if len(entry.LinkedIssue) == 1 {
_, err := ExtactEventNumber("issue", entry.LinkedIssue[0])
Copy link
Member

Choose a reason for hiding this comment

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

nit: typo in function name. I tried to change all occurrences, but please double check!

Suggested change
_, err := ExtactEventNumber("issue", entry.LinkedIssue[0])
_, err := ExtractEventNumber("issue", entry.LinkedIssue[0])

@@ -161,6 +168,39 @@ func collectFragment(fs afero.Fs, path string, info os.FileInfo, err error, file
return nil
}

func ExtactEventNumber(linkType, eventURL string) (string, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func ExtactEventNumber(linkType, eventURL string) (string, error) {
func ExtractEventNumber(linkType, eventURL string) (string, error) {

func FindIssues(graphqlClient *github.ClientGraphQL, ctx context.Context, owner, name string, prID, issuesLen int) ([]int, error) {
issues, err := graphqlClient.PR.FindIssues(ctx, owner, name, prID, issuesLen)
func FindIssues(graphqlClient *github.ClientGraphQL, ctx context.Context, owner, name string, prURL string, issuesLen int) ([]string, error) {
prID, err := ExtactEventNumber("pr", prURL)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
prID, err := ExtactEventNumber("pr", prURL)
prID, err := ExtractEventNumber("pr", prURL)

@@ -161,6 +168,39 @@ func collectFragment(fs afero.Fs, path string, info os.FileInfo, err error, file
return nil
}

func ExtactEventNumber(linkType, eventURL string) (string, error) {
urlParts := strings.Split(eventURL, "/")
Copy link
Member

Choose a reason for hiding this comment

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

Would be better to use URL parsing here? https://gobyexample.com/url-parsing https://pkg.go.dev/net/url#URL

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

URL parsing unfortunately doesn't help much as I still have to split the link. I've added it as an additional validation for the link.

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it's necessary to add it as an additional step, I was wondering if it could be of help for instead of string matching, but as I see it is not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Alright, will also remove it.

case "pr":
return fmt.Sprintf("https://github.com/%s/%s/pull/%s", owner, repo, eventID)
default:
return ""
Copy link
Member

Choose a reason for hiding this comment

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

Instead of returning an empty string here, let's panic. This is a developer error (passing the wrong linkType value), returning an empty string would shadow the error, making it hard to back track. By panicking we signals developers the error.

Suggested change
return ""
panic("wrong linkType")

func FindOriginalPR(linkedPR int, owner, repo string, c *github.Client) (int, error) {
pr, _, err := c.PullRequests.Get(context.Background(), owner, repo, linkedPR)
func FindOriginalPR(prURL string, owner, repo string, c *github.Client) (string, error) {
linkedPR, err := ExtactEventNumber("pr", prURL)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
linkedPR, err := ExtactEventNumber("pr", prURL)
linkedPR, err := ExtractEventNumber("pr", prURL)

@@ -42,12 +44,12 @@ func EntryFromFragment(f fragment.File) Entry {
},
}

if f.Fragment.Pr > 0 {
e.LinkedPR = []int{f.Fragment.Pr}
if len(f.Fragment.Pr) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if len(f.Fragment.Pr) > 0 {
if f.Fragment.Pr != "" {

}

if f.Fragment.Issue > 0 {
e.LinkedIssue = []int{f.Fragment.Issue}
if len(f.Fragment.Issue) > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if len(f.Fragment.Issue) > 0 {
if f.Fragment.Issue != "" {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Will do, any particular reason for not using len? The logic appears identical in this case.

Copy link
Member

Choose a reason for hiding this comment

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

No change in behaviour but checking string length is not idiomatic in Go.

@endorama endorama removed this from the v0.3.0 milestone Sep 19, 2022
@@ -64,6 +64,19 @@ def get_event_timestamp(repository, event, number):
date = datetime.fromisoformat(data["closed_at"].replace('Z', '+00:00'))
return str(int(datetime.timestamp(date)))


def sanitize_title(title):
Copy link
Member

Choose a reason for hiding this comment

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

I'm doing the same in a separate PR #104 so I would not include this here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Please use it there if useful, will remove it now.

@endorama
Copy link
Member

@LucianPy also don't remove fragments here, I forgot to build the changelog for 0.2.1 and 0.2.2, I'll do it afterwards

@lucian-ioan lucian-ioan merged commit df9f0f9 into elastic:main Sep 20, 2022
@lucian-ioan lucian-ioan deleted the pr-issue-field-to-url branch October 26, 2022 07:19
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.

Use full URL for pr and issue field in Changelog Fragment & Changelog Entry
3 participants