summaryrefslogtreecommitdiff
path: root/gen.go
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-04-13 16:44:58 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-04-13 16:44:58 -0600
commitf5d74f69a285c944eac13e78f15f4c4be6134a21 (patch)
tree0fcc29852cd36becd3fb4199855482c3aaf588bf /gen.go
parentb1d829c8dd7c115779710314dbda2b034835ff1e (diff)
wip dates
Diffstat (limited to 'gen.go')
-rw-r--r--gen.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/gen.go b/gen.go
index dbddd3b..f82847e 100644
--- a/gen.go
+++ b/gen.go
@@ -3,12 +3,17 @@ package main
import (
"bytes"
_ "embed"
+ "encoding/json"
"fmt"
+ "io"
+ "net/http"
"net/url"
"os"
"path"
+ "regexp"
"sigs.k8s.io/yaml"
"strings"
+ "time"
"github.com/yuin/goldmark"
"html/template"
@@ -31,6 +36,56 @@ type Contribution struct {
Desc string `json:"desc"`
}
+var (
+ reGitHubPR = regexp.MustCompile(`^https://github.com/([^/?#]+)/([^/?#]+)/pull/([0-9]+)(?:\?[^#]*)?(?:#.*)?$`)
+ rePiperMailDate = regexp.MustCompile(`^\s*<I>([^<]+)</I>\s*$`)
+)
+
+func (c Contribution) SubmittedAt() (time.Time, error) {
+ if m := reGitHubPR.FindStringSubmatch(c.URLs[0]); m != nil {
+ user := m[1]
+ repo := m[2]
+ prnum := m[3]
+ resp, err := http.Get("https://api.github.com/repos/" + user + "/" + repo + "/pulls/" + prnum)
+ if err != nil {
+ return time.Time{}, err
+ }
+ if resp.StatusCode != http.StatusOK {
+ return time.Time{}, fmt.Errorf("unexpected HTTP status: %v", resp.Status)
+ }
+ jsonBytes, err := io.ReadAll(resp.Body)
+ if err != nil {
+ return time.Time{}, err
+ }
+ var obj struct {
+ CreatedAt time.Time `json:"created_at"`
+ }
+ if err := json.Unmarshal(jsonBytes, &obj); err != nil {
+ return time.Time{}, err
+ }
+ return obj.CreatedAt, nil
+ }
+ if strings.Contains(c.URLs[0], "/pipermail/") {
+ resp, err := http.Get(c.URLs[0])
+ if err != nil {
+ return time.Time{}, err
+ }
+ if resp.StatusCode != http.StatusOK {
+ return time.Time{}, fmt.Errorf("unexpected HTTP status: %v", resp.Status)
+ }
+ htmlBytes, err := io.ReadAll(resp.Body)
+ if err != nil {
+ return time.Time{}, err
+ }
+ for _, line := range strings.Split(string(htmlBytes), "\n") {
+ if m := rePiperMailDate.FindStringSubmatch(line); m != nil {
+ return time.Parse(time.UnixDate, m[1])
+ }
+ }
+ }
+ return time.Time{}, nil //fmt.Errorf("idk how to check")
+}
+
func ReadContribs(filename string) (Contribs, error) {
bs, err := os.ReadFile(filename)
if err != nil {