summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--cmd/generate/gitcache.go66
-rw-r--r--cmd/generate/src_contribs.go59
-rw-r--r--go.mod1
-rw-r--r--go.sum10
5 files changed, 132 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index ae353ee..92a23fe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,6 @@
/.sass-cache/
/.http-cache/
+/.git-cache/
/public/imworkingon/index.html
/public/imworkingon/imworkingon.css
diff --git a/cmd/generate/gitcache.go b/cmd/generate/gitcache.go
new file mode 100644
index 0000000..7caf024
--- /dev/null
+++ b/cmd/generate/gitcache.go
@@ -0,0 +1,66 @@
+package main
+
+import (
+ "fmt"
+ "os"
+ "os/exec"
+ "strings"
+
+ "git.mothstuff.lol/lukeshu/eclipse/lib/gitcache"
+)
+
+var gitFetched = map[string]struct{}{}
+
+var gitCache = &gitcache.Cache{
+ Dir: ".git-cache",
+}
+
+func withGit(u string, fn func(dir string) error) error {
+ if _, ok := gitFetched[u]; !ok {
+ if err := gitCache.Fetch(os.Stderr, u); err != nil {
+ return err
+ }
+ }
+ return gitCache.WithFastClone(os.Stderr, u, fn)
+}
+
+func getGitTagThatContainsAll(gitURL string, gitHashes ...string) (string, error) {
+ if len(gitHashes) == 0 {
+ return "", nil
+ }
+ var tag string
+ err := withGit(gitURL, func(dir string) error {
+ gitHash := gitHashes[0]
+ if len(gitHashes) > 1 {
+ cmdline := append([]string{"git", "merge-base", "--independent", "--"}, gitHashes...)
+ cmd := exec.Command(cmdline[0], cmdline[1:]...)
+ cmd.Dir = dir
+ var stdout strings.Builder
+ cmd.Stdout = &stdout
+ cmd.Stderr = os.Stderr
+ if err := cmd.Run(); err != nil {
+ return err
+ }
+ gitHash = strings.TrimSpace(stdout.String())
+ }
+ cmd := exec.Command("git", "for-each-ref",
+ "--count=1",
+ "--format=%(refname:lstrip=2)",
+ "--contains="+gitHash,
+ "refs/tags/",
+ )
+ cmd.Dir = dir
+ var stdout strings.Builder
+ cmd.Stdout = &stdout
+ cmd.Stderr = os.Stderr
+ if err := cmd.Run(); err != nil {
+ return err
+ }
+ tag = strings.TrimSpace(stdout.String())
+ return nil
+ })
+ if err != nil {
+ return "", fmt.Errorf("%q: %w", gitURL, err)
+ }
+ return tag, nil
+}
diff --git a/cmd/generate/src_contribs.go b/cmd/generate/src_contribs.go
index 760b56a..f201ab5 100644
--- a/cmd/generate/src_contribs.go
+++ b/cmd/generate/src_contribs.go
@@ -102,8 +102,9 @@ func (c Contribution) fetchStatus() (string, error) {
var obj struct {
// State values are "open" and "closed".
- State string `json:"state"`
- Merged bool `json:"merged"`
+ State string `json:"state"`
+ Merged bool `json:"merged"`
+ MergeCommitSha string `json:"merge_commit_sha"`
}
if err := httpGetJSON(urlStr, &obj); err != nil {
return "", err
@@ -111,7 +112,15 @@ func (c Contribution) fetchStatus() (string, error) {
ret := obj.State
if obj.Merged {
ret = "merged"
+ tag, err := getGitTagThatContainsAll("https://github.com/"+user+"/"+repo, obj.MergeCommitSha)
+ if err != nil {
+ return "", err
+ }
+ if tag != "" {
+ ret = "released in " + tag
+ }
}
+
return ret, nil
}
if m := reGitLabMR.FindStringSubmatch(c.URLs[0]); m != nil {
@@ -123,7 +132,9 @@ func (c Contribution) fetchStatus() (string, error) {
var obj struct {
// State values are "opened", "closed", "locked", and "merged".
- State string `json:"state"`
+ State string `json:"state"`
+ MergeCommitSha string `json:"merge_commit_sha"`
+ SquashCommitSha string `json:"squash_commit_sha"`
}
if err := httpGetJSON(urlStr, &obj); err != nil {
return "", err
@@ -133,13 +144,51 @@ func (c Contribution) fetchStatus() (string, error) {
if ret == "opened" {
ret = "open"
}
+
+ if ret == "merged" {
+ var mergeCommit string
+ if obj.MergeCommitSha != "" {
+ mergeCommit = obj.MergeCommitSha
+ }
+ if obj.SquashCommitSha != "" {
+ mergeCommit = obj.SquashCommitSha
+ }
+ if mergeCommit != "" {
+ tag, err := getGitTagThatContainsAll("https://"+authority+"/"+projectID+".git", mergeCommit)
+ if err != nil {
+ return "", err
+ }
+ if tag != "" {
+ ret = "released in " + tag
+ }
+ }
+ }
+
return ret, nil
}
if len(c.URLs) > 1 {
+ var gitURL string
+ var gitCommits []string
for _, u := range c.URLs[1:] {
- if reGitHubCommit.MatchString(u) {
- return "merged", nil
+ if m := reGitHubCommit.FindStringSubmatch(u); m != nil {
+ user := m[1]
+ repo := m[2]
+ hash := m[3]
+
+ gitURL = "https://github.com/" + user + "/" + repo
+ gitCommits = append(gitCommits, hash)
+ }
+ }
+ if len(gitCommits) > 0 {
+ ret := "merged"
+ tag, err := getGitTagThatContainsAll(gitURL, gitCommits...)
+ if err != nil {
+ return "", err
+ }
+ if tag != "" {
+ ret = "released in " + tag
}
+ return ret, nil
}
}
return "", fmt.Errorf("idk how to get status for %q", c.URLs[0])
diff --git a/go.mod b/go.mod
index 76a8828..fa81230 100644
--- a/go.mod
+++ b/go.mod
@@ -3,6 +3,7 @@ module git.lukeshu.com/www
go 1.22.2
require (
+ git.mothstuff.lol/lukeshu/eclipse v0.0.0-20240303070330-f6bd42f39823
github.com/alecthomas/assert/v2 v2.8.1
github.com/yuin/goldmark v1.7.1
sigs.k8s.io/yaml v1.4.0
diff --git a/go.sum b/go.sum
index b7034ba..890465d 100644
--- a/go.sum
+++ b/go.sum
@@ -1,14 +1,24 @@
+git.mothstuff.lol/lukeshu/eclipse v0.0.0-20240303070330-f6bd42f39823 h1:kHDM0Z9wXBsOeoPVjmGFKMkBwkEZuKkD2VqHYGwGkk8=
+git.mothstuff.lol/lukeshu/eclipse v0.0.0-20240303070330-f6bd42f39823/go.mod h1:7OmOIgnKwCEdffiyonQseVTJuu8iQCtk4Amp1cvEr9E=
github.com/alecthomas/assert/v2 v2.8.1 h1:YCxnYR6jjpfnEK5AK5SysALKdUEBPGH4Y7As6tBnDw0=
github.com/alecthomas/assert/v2 v2.8.1/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
+github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/yuin/goldmark v1.7.1 h1:3bajkSilaCbjdKVsKdZjZCLBNPL9pYzrCakKaf4U49U=
github.com/yuin/goldmark v1.7.1/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=