Skip to content
This repository was archived by the owner on Dec 10, 2024. It is now read-only.

Commit ceca19a

Browse files
committed
Implement function to get pull mirror details from a project
1 parent cec93a2 commit ceca19a

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

projects.go

+38-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"net/http"
2424
"time"
2525

26-
retryablehttp "github.com/hashicorp/go-retryablehttp"
26+
"github.com/hashicorp/go-retryablehttp"
2727
)
2828

2929
// ProjectsService handles communication with the repositories related methods
@@ -1955,6 +1955,43 @@ func (s *ProjectsService) ChangeAllowedApprovers(pid interface{}, opt *ChangeAll
19551955
return pa, resp, err
19561956
}
19571957

1958+
// ProjectPullMirrorDetails represent the details of the configuration pull mirror and its update status
1959+
//
1960+
// GitLab API docs: https://docs.gitlab.com/ee/api/projects.html#get-a-projects-pull-mirror-details
1961+
type ProjectPullMirrorDetails struct {
1962+
ID int `json:"id"`
1963+
LastError string `json:"last_error"`
1964+
LastSuccessfulUpdateAt *time.Time `json:"last_successful_update_at"`
1965+
LastUpdateAt *time.Time `json:"last_update_at"`
1966+
LastUpdateStartedAt *time.Time `json:"last_update_started_at"`
1967+
UpdateStatus string `json:"update_status"`
1968+
URL string `json:"url"`
1969+
}
1970+
1971+
// GetProjectPullMirrorDetails returns the pull mirror details
1972+
//
1973+
// GitLab API docs: https://docs.gitlab.com/ee/api/projects.html#get-a-projects-pull-mirror-details
1974+
func (s *ProjectsService) GetProjectPullMirrorDetails(pid interface{}, options ...RequestOptionFunc) (*ProjectPullMirrorDetails, *Response, error) {
1975+
project, err := parseID(pid)
1976+
if err != nil {
1977+
return nil, nil, err
1978+
}
1979+
u := fmt.Sprintf("projects/%s/mirror/pull", PathEscape(project))
1980+
1981+
req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
1982+
if err != nil {
1983+
return nil, nil, err
1984+
}
1985+
1986+
model := new(ProjectPullMirrorDetails)
1987+
resp, err := s.client.Do(req, model)
1988+
if err != nil {
1989+
return nil, resp, err
1990+
}
1991+
1992+
return model, resp, err
1993+
}
1994+
19581995
// StartMirroringProject start the pull mirroring process for a project.
19591996
//
19601997
// GitLab API docs:

projects_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,45 @@ func TestCreateProjectApprovalRule(t *testing.T) {
12831283
}
12841284
}
12851285

1286+
func TestGetProjectPullMirrorDetails(t *testing.T) {
1287+
mux, client := setup(t)
1288+
1289+
mux.HandleFunc("/api/v4/projects/1/mirror/pull", func(w http.ResponseWriter, r *http.Request) {
1290+
testMethod(t, r, http.MethodGet)
1291+
fmt.Fprint(w, `{
1292+
"id": 101486,
1293+
"last_error": null,
1294+
"last_successful_update_at": "2020-01-06T17:32:02.823Z",
1295+
"last_update_at": "2020-01-06T17:32:02.823Z",
1296+
"last_update_started_at": "2020-01-06T17:31:55.864Z",
1297+
"update_status": "finished",
1298+
"url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git"
1299+
}`)
1300+
})
1301+
1302+
pullMirror, _, err := client.Projects.GetProjectPullMirrorDetails(1)
1303+
if err != nil {
1304+
t.Errorf("Projects.GetProjectPullMirrorDetails returned error: %v", err)
1305+
}
1306+
1307+
wantLastSuccessfulUpdateAtTimestamp := time.Date(2020, 01, 06, 17, 32, 02, 823000000, time.UTC)
1308+
wantLastUpdateAtTimestamp := time.Date(2020, 01, 06, 17, 32, 02, 823000000, time.UTC)
1309+
wantLastUpdateStartedAtTimestamp := time.Date(2020, 01, 06, 17, 31, 55, 864000000, time.UTC)
1310+
want := &ProjectPullMirrorDetails{
1311+
ID: 101486,
1312+
LastError: "",
1313+
LastSuccessfulUpdateAt: &wantLastSuccessfulUpdateAtTimestamp,
1314+
LastUpdateAt: &wantLastUpdateAtTimestamp,
1315+
LastUpdateStartedAt: &wantLastUpdateStartedAtTimestamp,
1316+
UpdateStatus: "finished",
1317+
URL: "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git",
1318+
}
1319+
1320+
if !reflect.DeepEqual(want, pullMirror) {
1321+
t.Errorf("Projects.GetProjectPullMirrorDetails returned %+v, want %+v", pullMirror, want)
1322+
}
1323+
}
1324+
12861325
func TestCreateProjectApprovalRuleEligibleApprovers(t *testing.T) {
12871326
mux, client := setup(t)
12881327

0 commit comments

Comments
 (0)