Skip to content

Commit efb50a0

Browse files
committed
CLEANUP/MINOR: ci: backport question uses hardcoded versions now
1 parent 91c2e3d commit efb50a0

1 file changed

Lines changed: 11 additions & 100 deletions

File tree

cmd/gitlab-mr-checker/main.go

Lines changed: 11 additions & 100 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/v3"
3533
"github.com/joho/godotenv"
3634
)
3735

@@ -80,10 +78,6 @@ type GitlabLabel struct {
8078
Description string `json:"description,omitempty"` // omitempty handles cases where description might be null or absent
8179
}
8280

83-
type Support struct {
84-
Versions []string `yaml:"versions"`
85-
}
86-
8781
type MergeRequest struct {
8882
Description string `json:"description"`
8983
}
@@ -92,6 +86,16 @@ var baseURL string //nolint:gochecknoglobals
9286

9387
const LABEL_COLOR = "#8fbc8f" //nolint:revive
9488

89+
// supportedVersions lists the active client-native release lines for which
90+
// the bot will propose backports. Update this when a new release is cut
91+
// or an old one is EOL'd.
92+
var supportedVersions = []string{ //nolint:gochecknoglobals
93+
"5.1",
94+
"6.0",
95+
"6.2",
96+
"6.3",
97+
}
98+
9599
//nolint:modernize,perfsprint
96100
func main() {
97101
_ = godotenv.Overload()
@@ -121,26 +125,6 @@ func main() {
121125
os.Exit(1)
122126
}
123127

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

146130
CI_MERGE_REQUEST_IID_STR := os.Getenv("CI_MERGE_REQUEST_IID") //nolint:revive
@@ -163,8 +147,7 @@ func main() {
163147
backportLabels := map[string]struct{}{
164148
"backport-ee": {},
165149
}
166-
for _, version := range versions {
167-
ver := strconv.FormatUint(version.Major(), 10) + "." + strconv.FormatUint(version.Minor(), 10)
150+
for _, ver := range supportedVersions {
168151
question += "\n" + "| " + ver + " | " + "backport-" + ver + " |"
169152
backportLabels["backport-"+ver] = struct{}{}
170153
}
@@ -366,78 +349,6 @@ func getProjectlabels(backportLabels map[string]struct{}, projectID string) erro
366349
return nil
367350
}
368351

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

0 commit comments

Comments
 (0)