-
Notifications
You must be signed in to change notification settings - Fork 12
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
Conversation
Please also remove the |
internal/changelog/builder.go
Outdated
@@ -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]) |
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.
nit: typo in function name. I tried to change all occurrences, but please double check!
_, err := ExtactEventNumber("issue", entry.LinkedIssue[0]) | |
_, err := ExtractEventNumber("issue", entry.LinkedIssue[0]) |
internal/changelog/builder.go
Outdated
@@ -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) { |
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.
func ExtactEventNumber(linkType, eventURL string) (string, error) { | |
func ExtractEventNumber(linkType, eventURL string) (string, error) { |
internal/changelog/builder.go
Outdated
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) |
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.
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, "/") |
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.
Would be better to use URL parsing here? https://gobyexample.com/url-parsing https://pkg.go.dev/net/url#URL
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.
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.
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 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.
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.
Alright, will also remove it.
internal/changelog/builder.go
Outdated
case "pr": | ||
return fmt.Sprintf("https://github.com/%s/%s/pull/%s", owner, repo, eventID) | ||
default: | ||
return "" |
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.
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.
return "" | |
panic("wrong linkType") |
internal/changelog/builder.go
Outdated
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) |
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.
linkedPR, err := ExtactEventNumber("pr", prURL) | |
linkedPR, err := ExtractEventNumber("pr", prURL) |
internal/changelog/entry.go
Outdated
@@ -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 { |
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 len(f.Fragment.Pr) > 0 { | |
if f.Fragment.Pr != "" { |
internal/changelog/entry.go
Outdated
} | ||
|
||
if f.Fragment.Issue > 0 { | ||
e.LinkedIssue = []int{f.Fragment.Issue} | ||
if len(f.Fragment.Issue) > 0 { |
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 len(f.Fragment.Issue) > 0 { | |
if f.Fragment.Issue != "" { |
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.
Will do, any particular reason for not using len
? The logic appears identical in this case.
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.
No change in behaviour but checking string length is not idiomatic in Go.
acde685
to
b65ad1f
Compare
tools/asciidoc_to_fragments.py
Outdated
@@ -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): |
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'm doing the same in a separate PR #104 so I would not include this here
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.
Please use it there if useful, will remove it now.
@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 |
Closes #89