Skip to content

Commit 8ec3bde

Browse files
committed
CLEANUP/MINOR: ci: backport question uses hardcoded versions now
1 parent d174bb6 commit 8ec3bde

3 files changed

Lines changed: 5 additions & 104 deletions

File tree

cmd/gitlab-mr-checker/main.go

Lines changed: 5 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ import (
2626
"net/url"
2727
"os"
2828
"slices"
29-
"sort"
3029
"strconv"
3130
"strings"
3231
"time"
3332

34-
"github.com/Masterminds/semver"
3533
"github.com/joho/godotenv"
3634
)
3735

@@ -90,6 +88,8 @@ type MergeRequest struct {
9088

9189
var baseURL string
9290

91+
var supportedVersions = []string{"2.9", "3.0", "3.2", "3.3"}
92+
9393
const LABEL_COLOR = "#8fbc8f"
9494

9595
func main() {
@@ -120,27 +120,6 @@ func main() {
120120
os.Exit(1)
121121
}
122122

123-
docs, err := GetBranches()
124-
if err != nil {
125-
slog.Error(err.Error())
126-
os.Exit(1)
127-
}
128-
var versions []*semver.Version
129-
for _, r := range docs {
130-
v, err := semver.NewVersion(r)
131-
if err != nil {
132-
slog.Debug("could not parse branch name as semver, skipping", "branch", r, "error", err)
133-
continue
134-
}
135-
versions = append(versions, v)
136-
}
137-
138-
sort.Sort(semver.Collection(versions))
139-
// leave only last three since only those are maintained
140-
if len(versions) > 3 {
141-
versions = versions[len(versions)-3:]
142-
}
143-
144123
gitlabToken := os.Getenv("GITLAB_TOKEN")
145124

146125
CI_MERGE_REQUEST_IID_STR := os.Getenv("CI_MERGE_REQUEST_IID")
@@ -164,13 +143,10 @@ func main() {
164143
backportLabels := map[string]struct{}{
165144
"backport-ee": {},
166145
}
167-
for _, version := range versions {
168-
ver := strconv.Itoa(int(version.Major())) + "." + strconv.Itoa(int(version.Minor()))
169-
sb.WriteString("\n")
170-
sb.WriteString("| ")
146+
for _, ver := range supportedVersions {
147+
sb.WriteString("\n| ")
171148
sb.WriteString(ver)
172-
sb.WriteString(" | ")
173-
sb.WriteString("backport-")
149+
sb.WriteString(" | backport-")
174150
sb.WriteString(ver)
175151
sb.WriteString(" |")
176152
backportLabels["backport-"+ver] = struct{}{}
@@ -373,78 +349,6 @@ func getProjectlabels(backportLabels map[string]struct{}, projectID string) erro
373349
return nil
374350
}
375351

376-
func GetBranches() ([]string, error) {
377-
projectID := os.Getenv("CI_PROJECT_ID")
378-
token := os.Getenv("GITLAB_TOKEN")
379-
380-
if baseURL == "" || projectID == "" || token == "" {
381-
return nil, errors.New("one or more required environment variables are not set: CI_API_V4_URL, CI_PROJECT_ID, GITLAB_TOKEN")
382-
}
383-
384-
var branches []string
385-
client := &http.Client{}
386-
387-
nextPageURL := fmt.Sprintf("%s/projects/%s/repository/branches", baseURL, url.PathEscape(projectID))
388-
389-
for nextPageURL != "" {
390-
req, err := http.NewRequestWithContext(context.Background(), http.MethodGet, nextPageURL, nil) //nolint:gosec // URL constructed from trusted CI environment variables
391-
if err != nil {
392-
return nil, fmt.Errorf("failed to create request: %w", err)
393-
}
394-
req.Header.Add("PRIVATE-TOKEN", token) //nolint:canonicalheader
395-
396-
resp, err := client.Do(req) //nolint:gosec // URL constructed from trusted CI environment variables
397-
if err != nil {
398-
return nil, fmt.Errorf("failed to get branches: %w", err)
399-
}
400-
401-
if resp.StatusCode != http.StatusOK {
402-
body, _ := io.ReadAll(resp.Body)
403-
resp.Body.Close()
404-
return nil, fmt.Errorf("failed to get branches: status %s, body: %s", resp.Status, string(body))
405-
}
406-
407-
body, err := io.ReadAll(resp.Body)
408-
if err != nil {
409-
resp.Body.Close()
410-
return nil, fmt.Errorf("failed to read response body: %w", err)
411-
}
412-
resp.Body.Close()
413-
414-
type Branch struct {
415-
Name string `json:"name"`
416-
}
417-
var gitlabBranches []Branch
418-
err = json.Unmarshal(body, &gitlabBranches)
419-
if err != nil {
420-
return nil, fmt.Errorf("failed to unmarshal response body: %w", err)
421-
}
422-
423-
for _, b := range gitlabBranches {
424-
branches = append(branches, b.Name)
425-
}
426-
427-
// Check for the next page using Link header
428-
linkHeader := resp.Header.Get("Link")
429-
if linkHeader == "" {
430-
nextPageURL = ""
431-
continue
432-
}
433-
434-
links := strings.Split(linkHeader, ",")
435-
nextPageURL = ""
436-
for _, link := range links {
437-
parts := strings.Split(strings.TrimSpace(link), ";")
438-
if len(parts) == 2 && strings.TrimSpace(parts[1]) == `rel="next"` {
439-
nextPageURL = strings.Trim(parts[0], "<>")
440-
break
441-
}
442-
}
443-
}
444-
445-
return branches, nil
446-
}
447-
448352
const hello = `
449353
__ __ ____ _ _
450354
| \/ | _ \ ___| |__ ___ ___| | _____ _ __

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.26
55
require (
66
github.com/GehirnInc/crypt v0.0.0-20230320061759-8cc1b52080c5
77
github.com/KimMachineGun/automemlimit v0.7.4
8-
github.com/Masterminds/semver v1.5.0
98
github.com/aws/aws-sdk-go-v2 v1.39.2
109
github.com/aws/aws-sdk-go-v2/config v1.31.12
1110
github.com/aws/aws-sdk-go-v2/credentials v1.18.16

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ github.com/GehirnInc/crypt v0.0.0-20230320061759-8cc1b52080c5 h1:IEjq88XO4PuBDcv
2424
github.com/GehirnInc/crypt v0.0.0-20230320061759-8cc1b52080c5/go.mod h1:exZ0C/1emQJAw5tHOaUDyY1ycttqBAPcxuzf7QbY6ec=
2525
github.com/KimMachineGun/automemlimit v0.7.4 h1:UY7QYOIfrr3wjjOAqahFmC3IaQCLWvur9nmfIn6LnWk=
2626
github.com/KimMachineGun/automemlimit v0.7.4/go.mod h1:QZxpHaGOQoYvFhv/r4u3U0JTC2ZcOwbSr11UZF46UBM=
27-
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
28-
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
2927
github.com/aws/aws-sdk-go-v2 v1.39.2 h1:EJLg8IdbzgeD7xgvZ+I8M1e0fL0ptn/M47lianzth0I=
3028
github.com/aws/aws-sdk-go-v2 v1.39.2/go.mod h1:sDioUELIUO9Znk23YVmIk86/9DOpkbyyVb1i/gUNFXY=
3129
github.com/aws/aws-sdk-go-v2/config v1.31.12 h1:pYM1Qgy0dKZLHX2cXslNacbcEFMkDMl+Bcj5ROuS6p8=

0 commit comments

Comments
 (0)