Skip to content

Commit

Permalink
Only considers PRs that have been merged it listed on a commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ForestEckhardt committed Jun 13, 2024
1 parent cb6b4a9 commit fcb4f38
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 12 deletions.
8 changes: 6 additions & 2 deletions actions/tag/calculate-semver/entrypoint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ type Label struct {
}

type PullRequest struct {
Number int `json:"number"`
Labels []Label `json:"labels"`
MergedAt string `json:"merged_at"`
Number int `json:"number"`
Labels []Label `json:"labels"`
}

const (
Expand Down Expand Up @@ -231,6 +232,9 @@ func getPRsSinceLastRelease(client *http.Client, config Config, previous *semver
}

for _, pr := range commitPRs {
if pr.MergedAt == "" {
continue
}
for _, label := range pr.Labels {
newSize, err := labelToSize(label.Name)
if err != nil {
Expand Down
63 changes: 53 additions & 10 deletions actions/tag/calculate-semver/entrypoint/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestEntrypoint(t *testing.T) {
"/repos/some-org/some-patch-repo/compare/v1.2.3...some-ref-name",
"/repos/some-org/some-patch-repo/compare/v1.1.2...some-ref-name":
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, `{ "commits" : [{ "sha" : "abcdef"}, { "sha" : "ghijklm" }]}`)
fmt.Fprintln(w, `{ "commits" : [{ "sha" : "abcdef"}, { "sha" : "ghijklm" }, { "sha" : "openstill" }]}`)

case
"/repos/some-org/some-broken-pulls-repo/compare/v1.2.3...some-ref-name",
Expand All @@ -147,7 +147,8 @@ func TestEntrypoint(t *testing.T) {
"labels" : [
{ "name" : "semver:patch"},
{ "name" : "otherLabel" }
]
],
"merged_at" : "some-time"
}]`)

case "/repos/some-org/some-patch-repo/commits/ghijklm/pulls":
Expand All @@ -157,6 +158,16 @@ func TestEntrypoint(t *testing.T) {
"labels" : [
{ "name" : "semver:patch"},
{ "name" : "otherLabel" }
],
"merged_at" : "some-time"
}]`)

case "/repos/some-org/some-patch-repo/commits/openstill/pulls":
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, `[
{ "number" : 3,
"labels" : [
{ "name" : "otherLabel" }
]
}]`)

Expand All @@ -167,7 +178,8 @@ func TestEntrypoint(t *testing.T) {
"labels" : [
{ "name" : "semver:patch"},
{ "name" : "otherLabel" }
]
],
"merged_at" : "some-time"
}]`)

case "/repos/some-org/some-minor-repo/commits/ghijklm/pulls":
Expand All @@ -177,6 +189,16 @@ func TestEntrypoint(t *testing.T) {
"labels" : [
{ "name" : "semver:minor"},
{ "name" : "otherLabel" }
],
"merged_at" : "some-time"
}]`)

case "/repos/some-org/some-minor-repo/commits/openstill/pulls":
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, `[
{ "number" : 3,
"labels" : [
{ "name" : "otherLabel" }
]
}]`)

Expand All @@ -187,7 +209,8 @@ func TestEntrypoint(t *testing.T) {
"labels" : [
{ "name" : "semver:major"},
{ "name" : "otherLabel" }
]
],
"merged_at" : "some-time"
}]`)

case "/repos/some-org/some-major-repo/commits/ghijklm/pulls":
Expand All @@ -197,14 +220,27 @@ func TestEntrypoint(t *testing.T) {
"labels" : [
{ "name" : "semver:minor"},
{ "name" : "otherLabel" }
],
"merged_at" : "some-time"
}]`)

case "/repos/some-org/some-major-repo/commits/openstill/pulls":
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, `[
{ "number" : 3,
"labels" : [
{ "name" : "otherLabel" }
]
}]`)

case "/repos/some-org/some-no-label-repo/commits/abcdef/pulls":
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, `[
{ "number" : 1,
"labels" : [{ "name" : "otherLabel" }]
"labels" : [
{ "name" : "otherLabel" }
],
"merged_at" : "some-time"
}]`)

case "/repos/some-org/some-many-label-repo/commits/abcdef/pulls":
Expand All @@ -213,7 +249,10 @@ func TestEntrypoint(t *testing.T) {
{ "number" : 1,
"labels" : [
{ "name" : "semver:minor" },
{ "name" : "semver:major" }]}]`)
{ "name" : "semver:major" }
],
"merged_at" : "some-time"
}]`)

case
"/repos/some-org/some-broken-commits-repo/compare/v1.2.3...some-ref-name",
Expand Down Expand Up @@ -265,13 +304,14 @@ func TestEntrypoint(t *testing.T) {

Eventually(session).Should(gexec.Exit(0), func() string { return fmt.Sprintf("output -> \n%s\n", buffer.Contents()) })

Expect(requests).To(HaveLen(5))
Expect(requests).To(HaveLen(6))

Expect(requests[0].URL.Path).To(Equal("/repos/some-org/some-patch-repo"))
Expect(requests[1].URL.Path).To(Equal("/repos/some-org/some-patch-repo/releases"))
Expect(requests[2].URL.Path).To(Equal("/repos/some-org/some-patch-repo/compare/v1.2.3...some-ref-name"))
Expect(requests[3].URL.Path).To(Equal("/repos/some-org/some-patch-repo/commits/abcdef/pulls"))
Expect(requests[4].URL.Path).To(Equal("/repos/some-org/some-patch-repo/commits/ghijklm/pulls"))
Expect(requests[5].URL.Path).To(Equal("/repos/some-org/some-patch-repo/commits/openstill/pulls"))

outputContains(`tag=1.2.4`)
})
Expand All @@ -298,13 +338,14 @@ func TestEntrypoint(t *testing.T) {

Eventually(session).Should(gexec.Exit(0), func() string { return fmt.Sprintf("output -> \n%s\n", buffer.Contents()) })

Expect(requests).To(HaveLen(5))
Expect(requests).To(HaveLen(6))

Expect(requests[0].URL.Path).To(Equal("/repos/some-org/some-minor-repo"))
Expect(requests[1].URL.Path).To(Equal("/repos/some-org/some-minor-repo/releases"))
Expect(requests[2].URL.Path).To(Equal("/repos/some-org/some-minor-repo/compare/v1.2.3...some-ref-name"))
Expect(requests[3].URL.Path).To(Equal("/repos/some-org/some-minor-repo/commits/abcdef/pulls"))
Expect(requests[4].URL.Path).To(Equal("/repos/some-org/some-minor-repo/commits/ghijklm/pulls"))
Expect(requests[5].URL.Path).To(Equal("/repos/some-org/some-minor-repo/commits/openstill/pulls"))

outputContains(`tag=1.3.0`)
})
Expand All @@ -331,13 +372,14 @@ func TestEntrypoint(t *testing.T) {

Eventually(session).Should(gexec.Exit(0), func() string { return fmt.Sprintf("output -> \n%s\n", buffer.Contents()) })

Expect(requests).To(HaveLen(5))
Expect(requests).To(HaveLen(6))

Expect(requests[0].URL.Path).To(Equal("/repos/some-org/some-major-repo"))
Expect(requests[1].URL.Path).To(Equal("/repos/some-org/some-major-repo/releases"))
Expect(requests[2].URL.Path).To(Equal("/repos/some-org/some-major-repo/compare/v1.2.3...some-ref-name"))
Expect(requests[3].URL.Path).To(Equal("/repos/some-org/some-major-repo/commits/abcdef/pulls"))
Expect(requests[4].URL.Path).To(Equal("/repos/some-org/some-major-repo/commits/ghijklm/pulls"))
Expect(requests[5].URL.Path).To(Equal("/repos/some-org/some-major-repo/commits/openstill/pulls"))

outputContains(`tag=2.0.0`)
})
Expand Down Expand Up @@ -456,13 +498,14 @@ func TestEntrypoint(t *testing.T) {

Eventually(session).Should(gexec.Exit(0), func() string { return fmt.Sprintf("output -> \n%s\n", buffer.Contents()) })

Expect(requests).To(HaveLen(5))
Expect(requests).To(HaveLen(6))

Expect(requests[0].URL.Path).To(Equal("/repos/some-org/some-patch-repo"))
Expect(requests[1].URL.Path).To(Equal("/repos/some-org/some-patch-repo/releases"))
Expect(requests[2].URL.Path).To(Equal("/repos/some-org/some-patch-repo/compare/v1.1.2...some-ref-name"))
Expect(requests[3].URL.Path).To(Equal("/repos/some-org/some-patch-repo/commits/abcdef/pulls"))
Expect(requests[4].URL.Path).To(Equal("/repos/some-org/some-patch-repo/commits/ghijklm/pulls"))
Expect(requests[5].URL.Path).To(Equal("/repos/some-org/some-patch-repo/commits/openstill/pulls"))

outputContains(`tag=1.1.3`)
})
Expand Down

0 comments on commit fcb4f38

Please sign in to comment.