File: schedule.go

package info (click to toggle)
glab 1.53.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 20,936 kB
  • sloc: sh: 295; makefile: 153; perl: 99; ruby: 68; javascript: 67
file content (112 lines) | stat: -rw-r--r-- 3,461 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package api

import (
	"fmt"

	gitlab "gitlab.com/gitlab-org/api/client-go"
)

var GetSchedules = func(client *gitlab.Client, l *gitlab.ListPipelineSchedulesOptions, repo string) ([]*gitlab.PipelineSchedule, error) {
	if client == nil {
		client = apiClient.Lab()
	}
	if l.PerPage == 0 {
		l.PerPage = DefaultListLimit
	}

	schedules, _, err := client.PipelineSchedules.ListPipelineSchedules(repo, l)
	if err != nil {
		return nil, err
	}
	return schedules, nil
}

var RunSchedule = func(client *gitlab.Client, repo string, schedule int, opts ...gitlab.RequestOptionFunc) error {
	if client == nil {
		client = apiClient.Lab()
	}

	_, err := client.PipelineSchedules.RunPipelineSchedule(repo, schedule, opts...)
	if err != nil {
		return fmt.Errorf("running scheduled pipeline status: %w", err)
	}

	return nil
}

var CreateSchedule = func(client *gitlab.Client, repo string, scheduleOpts *gitlab.CreatePipelineScheduleOptions, opts ...gitlab.RequestOptionFunc) (error, *gitlab.PipelineSchedule) {
	if client == nil {
		client = apiClient.Lab()
	}

	schedule, _, err := client.PipelineSchedules.CreatePipelineSchedule(repo, scheduleOpts, opts...)
	if err != nil {
		return fmt.Errorf("creating scheduled pipeline status: %w", err), nil
	}

	return nil, schedule
}

var EditSchedule = func(client *gitlab.Client, repo string, scheduleId int, scheduleOpts *gitlab.EditPipelineScheduleOptions, opts ...gitlab.RequestOptionFunc) (*gitlab.PipelineSchedule, error) {
	if client == nil {
		client = apiClient.Lab()
	}

	schedule, _, err := client.PipelineSchedules.EditPipelineSchedule(repo, scheduleId, scheduleOpts, opts...)
	if err != nil {
		return nil, fmt.Errorf("editing scheduled pipeline status: %w", err)
	}

	return schedule, nil
}

var CreateScheduleVariable = func(client *gitlab.Client, repo string, scheduleId int, scheduleVarOpts *gitlab.CreatePipelineScheduleVariableOptions, opts ...gitlab.RequestOptionFunc) error {
	if client == nil {
		client = apiClient.Lab()
	}

	_, _, err := client.PipelineSchedules.CreatePipelineScheduleVariable(repo, scheduleId, scheduleVarOpts, opts...)
	if err != nil {
		return fmt.Errorf("creating scheduled pipeline status: %w", err)
	}

	return nil
}

var EditScheduleVariable = func(client *gitlab.Client, repo string, scheduleId int, variableKey string, scheduleVarOpts *gitlab.EditPipelineScheduleVariableOptions, opts ...gitlab.RequestOptionFunc) error {
	if client == nil {
		client = apiClient.Lab()
	}

	_, _, err := client.PipelineSchedules.EditPipelineScheduleVariable(repo, scheduleId, variableKey, scheduleVarOpts, opts...)
	if err != nil {
		return fmt.Errorf("editing scheduled pipeline status: %w", err)
	}

	return nil
}

var DeleteScheduleVariable = func(client *gitlab.Client, repo string, scheduleId int, variableKey string, opts ...gitlab.RequestOptionFunc) (err error) {
	if client == nil {
		client = apiClient.Lab()
	}

	_, _, err = client.PipelineSchedules.DeletePipelineScheduleVariable(repo, scheduleId, variableKey, opts...)
	if err != nil {
		return fmt.Errorf("deleting scheduled pipeline status: %w", err)
	}

	return nil
}

var DeleteSchedule = func(client *gitlab.Client, scheduleId int, repo string, opts ...gitlab.RequestOptionFunc) (err error) {
	if client == nil {
		client = apiClient.Lab()
	}

	_, err = client.PipelineSchedules.DeletePipelineSchedule(repo, scheduleId, opts...)
	if err != nil {
		return fmt.Errorf("deleting scheduled pipeline status: %w", err)
	}
	return nil
}