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

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: xanzy/go-gitlab
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.92.3
Choose a base ref
...
head repository: xanzy/go-gitlab
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.93.0
Choose a head ref
  • 7 commits
  • 7 files changed
  • 4 contributors

Commits on Oct 3, 2023

  1. Fixes #1811

    svanharmelen committed Oct 3, 2023
    Copy the full SHA
    8cb9c32 View commit details

Commits on Oct 4, 2023

  1. Copy the full SHA
    c92eb1b View commit details
  2. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6aff7b6 View commit details
  3. Merge pull request #1815 from xuxiaowei-com-cn/xuxiaowei/DeleteProjec…

    …tArtifacts
    
    ✨ delete artifacts eligible for deletion in a project
    svanharmelen authored Oct 4, 2023
    Copy the full SHA
    9085e18 View commit details
  4. Merge pull request #1813 from mitar/patch-1

    Make sure response is fully consumed
    svanharmelen authored Oct 4, 2023
    Copy the full SHA
    285184d View commit details

Commits on Oct 5, 2023

  1. Copy the full SHA
    bce1c13 View commit details
  2. Merge pull request #1814 from timofurrer/feature/user-pat

    Support CreatePersonalAccessTokenForCurrentUser endpoint
    svanharmelen authored Oct 5, 2023
    Copy the full SHA
    e104217 View commit details
Showing with 106 additions and 7 deletions.
  1. +1 −0 gitlab.go
  2. +19 −0 jobs.go
  3. +4 −4 merge_requests.go
  4. +3 −3 merge_requests_test.go
  5. +13 −0 testdata/post_user_personal_access_tokens.json
  6. +32 −0 users.go
  7. +34 −0 users_test.go
1 change: 1 addition & 0 deletions gitlab.go
Original file line number Diff line number Diff line change
@@ -813,6 +813,7 @@ func (c *Client) Do(req *retryablehttp.Request, v interface{}) (*Response, error
return c.Do(req, v)
}
defer resp.Body.Close()
defer io.Copy(io.Discard, resp.Body)

// If not yet configured, try to configure the rate limiter
// using the response headers we just received. Fail silently
19 changes: 19 additions & 0 deletions jobs.go
Original file line number Diff line number Diff line change
@@ -564,3 +564,22 @@ func (s *JobsService) DeleteArtifacts(pid interface{}, jobID int, options ...Req

return s.client.Do(req, nil)
}

// DeleteProjectArtifacts delete artifacts eligible for deletion in a project
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/job_artifacts.html#delete-project-artifacts
func (s *JobsService) DeleteProjectArtifacts(pid interface{}, options ...RequestOptionFunc) (*Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, err
}
u := fmt.Sprintf("projects/%s/artifacts", PathEscape(project))

req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
if err != nil {
return nil, err
}

return s.client.Do(req, nil)
}
8 changes: 4 additions & 4 deletions merge_requests.go
Original file line number Diff line number Diff line change
@@ -493,18 +493,18 @@ func (s *MergeRequestsService) GetMergeRequestChanges(pid interface{}, mergeRequ
return m, resp, nil
}

// ListMergeRequesDiffsOptions represents the available ListMergeRequesDiffs()
// ListMergeRequestDiffsOptions represents the available ListMergeRequesDiffs()
// options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/merge_requests.html#list-merge-request-diffs
type ListMergeRequesDiffsOptions ListOptions
type ListMergeRequestDiffsOptions ListOptions

// ListMergeRequesDiffs List diffs of the files changed in a merge request
// ListMergeRequestDiffs List diffs of the files changed in a merge request
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/merge_requests.html#list-merge-request-diffs
func (s *MergeRequestsService) ListMergeRequesDiffs(pid interface{}, mergeRequest int, opt *ListMergeRequesDiffsOptions, options ...RequestOptionFunc) ([]*MergeRequestDiff, *Response, error) {
func (s *MergeRequestsService) ListMergeRequestDiffs(pid interface{}, mergeRequest int, opt *ListMergeRequestDiffsOptions, options ...RequestOptionFunc) ([]*MergeRequestDiff, *Response, error) {
project, err := parseID(pid)
if err != nil {
return nil, nil, err
6 changes: 3 additions & 3 deletions merge_requests_test.go
Original file line number Diff line number Diff line change
@@ -260,7 +260,7 @@ func TestGetMergeRequestReviewers(t *testing.T) {
log.Fatal(err)
}

createdAt := time.Date(2022, 07, 27, 17, 3, 27, 684000000, time.UTC)
createdAt := time.Date(2022, 0o7, 27, 17, 3, 27, 684000000, time.UTC)
user1 := BasicUser{ID: 1, Name: "John Doe1", Username: "user1", State: "active", AvatarURL: "http://www.gravatar.com/avatar/c922747a93b40d1ea88262bf1aebee62?s=80&d=identicon", WebURL: "http://localhost/user1"}
user2 := BasicUser{ID: 2, Name: "John Doe2", Username: "user2", State: "active", AvatarURL: "http://www.gravatar.com/avatar/10fc7f102be8de7657fb4d80898bbfe3?s=80&d=identicon", WebURL: "http://localhost/user2"}

@@ -296,12 +296,12 @@ func TestListMergeRequesDiffs(t *testing.T) {
mustWriteHTTPResponse(t, w, "testdata/list_merge_request_diff.json")
})

opts := &ListMergeRequesDiffsOptions{
opts := &ListMergeRequestDiffsOptions{
Page: 1,
PerPage: 2,
}

diffs, _, err := client.MergeRequests.ListMergeRequesDiffs(1, 1, opts)
diffs, _, err := client.MergeRequests.ListMergeRequestDiffs(1, 1, opts)
if err != nil {
t.Errorf("MergeRequests.ListMergeRequesDiffs returned error: %v", err)
}
13 changes: 13 additions & 0 deletions testdata/post_user_personal_access_tokens.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"id": 3,
"name": "mytoken",
"revoked": false,
"created_at": "2020-10-14T11:58:53.526Z",
"scopes": [
"k8s_proxy"
],
"user_id": 42,
"active": true,
"expires_at": "2020-10-15",
"token": "glpat-aaaaaaaa-bbbbbbbbb"
}
32 changes: 32 additions & 0 deletions users.go
Original file line number Diff line number Diff line change
@@ -1301,6 +1301,38 @@ func (s *UsersService) CreatePersonalAccessToken(user int, opt *CreatePersonalAc
return t, resp, nil
}

// CreatePersonalAccessTokenForCurrentUserOptions represents the available
// CreatePersonalAccessTokenForCurrentUser() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/users.html#create-a-personal-access-token-with-limited-scopes-for-the-currently-authenticated-user
type CreatePersonalAccessTokenForCurrentUserOptions struct {
Name *string `url:"name,omitempty" json:"name,omitempty"`
Scopes *[]string `url:"scopes,omitempty" json:"scopes,omitempty"`
ExpiresAt *ISOTime `url:"expires_at,omitempty" json:"expires_at,omitempty"`
}

// CreatePersonalAccessTokenForCurrentUser creates a personal access token with limited scopes for the currently authenticated user.
//
// GitLab API docs:
// https://docs.gitlab.com/ee/api/users.html#create-a-personal-access-token-with-limited-scopes-for-the-currently-authenticated-user
func (s *UsersService) CreatePersonalAccessTokenForCurrentUser(opt *CreatePersonalAccessTokenForCurrentUserOptions, options ...RequestOptionFunc) (*PersonalAccessToken, *Response, error) {
u := "user/personal_access_tokens"

req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
if err != nil {
return nil, nil, err
}

t := new(PersonalAccessToken)
resp, err := s.client.Do(req, &t)
if err != nil {
return nil, resp, err
}

return t, resp, nil
}

// UserActivity represents an entry in the user/activities response
//
// GitLab API docs:
34 changes: 34 additions & 0 deletions users_test.go
Original file line number Diff line number Diff line change
@@ -682,3 +682,37 @@ func TestCreateUserRunner(t *testing.T) {
require.Equal(t, "glrt-1234567890ABCD", response.Token)
require.Equal(t, (*time.Time)(nil), response.TokenExpiresAt)
}

func TestCreatePersonalAccessTokenForCurrentUser(t *testing.T) {
mux, client := setup(t)

path := "/api/v4/user/personal_access_tokens"

mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPost)
mustWriteHTTPResponse(t, w, "testdata/post_user_personal_access_tokens.json")
})

scopes := []string{"k8s_proxy"}
expiresAt := ISOTime(time.Date(2020, time.October, 15, 0, 0, 0, 0, time.UTC))
user, _, err := client.Users.CreatePersonalAccessTokenForCurrentUser(&CreatePersonalAccessTokenForCurrentUserOptions{
Name: String("mytoken"),
Scopes: &scopes,
ExpiresAt: &expiresAt,
})
require.NoError(t, err)

createdAt := time.Date(2020, time.October, 14, 11, 58, 53, 526000000, time.UTC)
want := &PersonalAccessToken{
ID: 3,
Name: "mytoken",
Revoked: false,
CreatedAt: &createdAt,
Scopes: scopes,
UserID: 42,
Active: true,
ExpiresAt: &expiresAt,
Token: "glpat-aaaaaaaa-bbbbbbbbb",
}
require.Equal(t, want, user)
}