@@ -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
9189var baseURL string
9290
91+ var supportedVersions = []string {"2.9" , "3.0" , "3.2" , "3.3" }
92+
9393const LABEL_COLOR = "#8fbc8f"
9494
9595func 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-
448352const hello = `
449353 __ __ ____ _ _
450354| \/ | _ \ ___| |__ ___ ___| | _____ _ __
0 commit comments