xanzy / go-gitlab Goto Github PK
View Code? Open in Web Editor NEWGitLab Go SDK
License: Apache License 2.0
GitLab Go SDK
License: Apache License 2.0
I think we should change fields in structs to use pointers and so distinguish between nil and empty values.
The same approach is used in go-github repository.
Here you can find detailed blog why it is good to use pointers:
https://willnorris.com/2014/05/go-rest-apis-and-pointers
It's also problem in go-gitlab.
For example you cannot edit existing project's description and change it to empty string, because empty description value will never be sent to server (will be omitted).
What do you think ?
Hi,
When I added a webhook to the group (not a project) Gitlab give me different type of json.
Here is example.
{ "object_kind": "merge_request", "user": { "name": "Administrator", "username": "root", "avatar_url": "http://www.gravatar.com/avatar/d22738dc40839e3d95fca77ca3eac067?s=80\u0026d=identicon" }, "project": { "name": "example-project", "description": "", "web_url": "http://example.com/exm-namespace/example-project", "avatar_url": null, "git_ssh_url": "[email protected]:exm-namespace/example-project.git", "git_http_url": "http://example.com/exm-namespace/example-project.git", "namespace": "exm-namespace", "visibility_level": 0, "path_with_namespace": "exm-namespace/example-project", "default_branch": "master", "homepage": "http://example.com/exm-namespace/example-project", "url": "[email protected]:exm-namespace/example-project.git", "ssh_url": "[email protected]:exm-namespace/example-project.git", "http_url": "http://example.com/exm-namespace/example-project.git" }, "object_attributes": { "id": 15917, "target_branch ": "master ", "source_branch ": "source-branch-test ", "source_project_id ": 87, "author_id ": 15, "assignee_id ": 29, "title ": "source-branch-test ", "created_at ": "2016 - 12 - 01 13: 11: 10 UTC ", "updated_at ": "2016 - 12 - 01 13: 21: 20 UTC ", "milestone_id ": null, "state ": "merged ", "merge_status ": "can_be_merged ", "target_project_id ": 87, "iid ": 1402, "description ": "word doc support for e - ticket ", "position ": 0, "locked_at ": null, "updated_by_id ": null, "merge_error ": null, "merge_params": { "force_remove_source_branch": "0" }, "merge_when_build_succeeds": false, "merge_user_id": null, "merge_commit_sha": "ac3ca1559bc39abf963586372eff7f8fdded646e", "deleted_at": null, "approvals_before_merge": null, "rebase_commit_sha": null, "in_progress_merge_commit_sha": null, "lock_version": 0, "time_estimate": 0, "source": { "name": "example-project", "description": "", "web_url": "http://example.com/exm-namespace/example-project", "avatar_url": null, "git_ssh_url": "[email protected]:exm-namespace/example-project.git", "git_http_url": "http://example.com/exm-namespace/example-project.git", "namespace": "exm-namespace", "visibility_level": 0, "path_with_namespace": "exm-namespace/example-project", "default_branch": "master", "homepage": "http://example.com/exm-namespace/example-project", "url": "[email protected]:exm-namespace/example-project.git", "ssh_url": "[email protected]:exm-namespace/example-project.git", "http_url": "http://example.com/exm-namespace/example-project.git" }, "target": { "name": "example-project", "description": "", "web_url": "http://example.com/exm-namespace/example-project", "avatar_url": null, "git_ssh_url": "[email protected]:exm-namespace/example-project.git", "git_http_url": "http://example.com/exm-namespace/example-project.git", "namespace": "exm-namespace", "visibility_level": 0, "path_with_namespace": "exm-namespace/example-project", "default_branch": "master", "homepage": "http://example.com/exm-namespace/example-project", "url": "[email protected]:exm-namespace/example-project.git", "ssh_url": "[email protected]:exm-namespace/example-project.git", "http_url": "http://example.com/exm-namespace/example-project.git" }, "last_commit": { "id": "61b6a0d35dbaf915760233b637622e383d3cc9ec", "message": "commit message", "timestamp": "2016-12-01T15:07:53+02:00", "url": "http://example.com/exm-namespace/example-project/commit/61b6a0d35dbaf915760233b637622e383d3cc9ec", "author": { "name": "Test User", "email": "[email protected]" } }, "work_in_progress": false, "url": "http://example.com/exm-namespace/example-project/merge_requests/1402", "action": "merge" }, "repository": { "name": "example-project", "url": "[email protected]:exm-namespace/example-project.git", "description": "", "homepage": "http://example.com/exm-namespace/example-project" }, "assignee": { "name": "Administrator", "username": "root", "avatar_url": "http://www.gravatar.com/avatar/d22738dc40839e3d95fca77ca3eac067?s=80\u0026d=identicon" } }
events.go --MergeEvent cannot unmarshal the json.
e.g. ListMergeRequests
and ListProjectIssues
, when they both work with projects. Either make both have Project
, or neither.
Lets track this in an issue. The GitLab API v3 is officially deprecated and will be supported until at least 9.3. Given the current release schedule (once per month), that means it will be unsupported 3 months from now.
I would like to be able to start consuming v4 functionality so I might start work on a v4 branch.
I think all current documentation links need to be updated to the v3 documentation as currently the links all point to the v4 documentation which causes confusion. Separately some effort should be made to start supporting v4 specific functionality (probably in a feature branch). Once both those things are completed, v3 could be spun out to a separate branch and v4 can be merged to master.
Below are the changes made between V3 and V4. A tickbox indicates that work has been completed on that change.
POST /projects/:id/trigger/builds
to POST /projects/:id/trigger/pipeline
POST /projects/:id/triggers
GET /projects/:search
(use: GET /projects?search=x
) !8877. Fixed in #161.iid
filter has been removed from GET /projects/:id/issues
!8967. Fixed in #161.GET /projects/:id/merge_requests?iid[]=x&iid[]=y
array filter has been renamed to iids
!8793. Fixed in #161.GET /projects/merge_request/:id
have been removed (use: GET /projects/merge_requests/:id
) !8793. Fixed in #161.expires_at
!8723. Fixed in #161.GET /projects/:id/keys
have been removed (use GET /projects/:id/deploy_keys
) !8716. Fixed in #161.GET /projects/:id/pipelines
!8875. Fixed in #163build
references to job
!9463. Fixed in #166.visibility
as string parameter everywhere !9337. Fixed in #167.GET /projects/foo
, but as GET /projects?foo=true
instead !8962. Fixed in #170.
GET /projects/visible
& GET /projects/all
are consolidated into GET /projects
and can be used with or without authorizationGET /projects/owned
moved to GET /projects?owned=true
GET /projects/starred
moved to GET /projects?starred=true
GET /projects
returns all projects visible to current user, even if the user is not a member !9674. Fixed in #170.
GET /projects?membership=true
400
for all validation errors when creating or updating a member instead of sometimes 422
error. !9523. Doesn't require changes.POST /projects/:id/members
when a member already exists !9093. Doesn't require changes.GET /groups/owned
. Use GET /groups?owned=true
instead !9505. Fixed in commit 62634b8.POST /projects/fork/:id
to POST /projects/:id/fork
!8940. Fixed in commit 577e19d.merge_when_build_succeeds
parameter to merge_when_pipeline_succeeds
on the following endpoints: !9335
PUT /projects/:id/merge_requests/:merge_request_id/merge
POST /projects/:id/merge_requests/:merge_request_id/cancel_merge_when_pipeline_succeeds
POST /projects
POST /projects/user/:user_id
PUT /projects/:id
GET /projects/:id/repository/files?file_path=:file_path
to GET /projects/:id/repository/files/:file_path
(:file_path
should be URL-encoded)GET /projects/:id/repository/blobs/:sha
now returns JSON attributes for the blob identified by :sha
, instead of finding the commit identified by :sha
and returning the raw content of the blob in that commit identified by the required ?filepath=:filepath
GET /projects/:id/repository/commits/:sha/blob?file_path=:file_path
and GET /projects/:id/repository/blobs/:sha?file_path=:file_path
to GET /projects/:id/repository/files/:file_path/raw?ref=:sha
GET /projects/:id/repository/tree
parameter ref_name
has been renamed to ref
for consistency/templates
prefix) !8853
/licences
/licences/:key
/gitignores
/gitlab_ci_ymls
/dockerfiles
/gitignores/:key
/gitlab_ci_ymls/:key
/dockerfiles/:key
DELETE /todos
to POST /todos/mark_as_done
and DELETE /todos/:todo_id
to POST /todos/:todo_id/mark_as_done
!9410DELETE /projects/:id/deploy_keys/:key_id/disable
. Use DELETE /projects/:id/deploy_keys/:key_id
instead !9366PUT /users/:id/(block|unblock)
to POST /users/:id/(block|unblock)
!9371POST /projects/:id/:subscribable_type/:subscribable_id/subscribe
to subscribe and POST /projects/:id/:subscribable_type/:subscribable_id/unsubscribe
to unsubscribe from a resource. !9325GET /projects/:id/issues
and GET /issues
now matches only issues containing all labels (i.e.: Logical AND, not OR) !8849branch_name
to branch
on the following endpoints !8936
POST /projects/:id/repository/branches
POST /projects/:id/repository/commits
POST/PUT/DELETE :id/repository/files
branch_name
to branch
on DELETE /projects/:id/repository/branches/:branch
response !8936public
param from create and edit actions of projects !8736subscribed
field from responses returning list of issues or mergesubscribed
upvote
and downvote
!9384DELETE /projects/:id/repository/merged_branches
and DELETE /projects/:id
) !9449GET /projects/:id/milestones?iid[]=x&iid[]=y
array filter has been renamed to iids
!9096GET /projects/:id/repository/commits/:sha/jobs
!9463IID
s (internal ID, as in the web UI) rather than ID
s. This affects the merge requests, award emoji, todos, and time tracking APIs. !9530IID
s (internal ID, as in the web UI) rather than ID
s. This affects the issues, award emoji, todos, and time tracking APIs. !95300
to 1
on GET /projects/:id/repository/commits
(like on the rest of the API) [!9679] (https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/9679)Link
header data for GET /projects/:id/repository/commits
[!9679] (https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/9679)project, _, err := git.Projects.GetProject("georg/test-timetracking")
Expect(err).NotTo(HaveOccurred())
Expect(*(project.Name)).To(Equal("test-timetracking"))
_, _, err = git.Issues.CreateIssue(
"georg/test-timetracking",
&gitlab.CreateIssueOptions{
Title: "Hello World",
Description: "I am the Description",
AssigneeID: 2,
},
)
Expect(err).NotTo(HaveOccurred())
Why does this result in an error 500? How do I create a new Issue then?
Hi .. This is more a question than an issue.
When we interact with our gitlab api, the api returns the work_in_progress
attribute as 0
(if true) or null
(if false). This means the unmarshal'ing returns an error. We've fixed the issue on our forked repo by just adding the type int
instead of bool
. (Although it clearly states it should return a boolean)
I havent made a pull request because no one else has complained or notified about this, so we we're wondering if it was a problem on our side. Has anyone stumbled across this?
Also, thank you for making this an open source project ๐ป
Hello,
Just to make things cleaner :) Otherwise, using the AccessLevel type in comparisons requires extra casting. Unless I'm doing things wrong, that is :) Here's a bit of code:
if gitlab.AccessLevel(gus[i].AccessLevel) >= gitlab.MasterPermissions {
...
}
Would be easier to read as:
if gus[i].AccessLevel >= gitlab.MasterPermissions {
...
}
Thanks,
Clรฉment
The Add project hook API endpoint supports a token
parameter, however, this property is missing from the AddProjectHookOptions
and EditProjectHookOptions
types.
Can you please update these structs to include the Token field?
type AddProjectHookOptions struct {
URL *string `url:"url,omitempty" json:"url,omitempty"`
PushEvents *bool `url:"push_events,omitempty" json:"push_events,omitempty"`
IssuesEvents *bool `url:"issues_events,omitempty" json:"issues_events,omitempty"`
MergeRequestsEvents *bool `url:"merge_requests_events,omitempty" json:"merge_requests_events,omitempty"`
TagPushEvents *bool `url:"tag_push_events,omitempty" json:"tag_push_events,omitempty"`
NoteEvents *bool `url:"note_events,omitempty" json:"note_events,omitempty"`
BuildEvents *bool `url:"build_events,omitempty" json:"build_events,omitempty"`
PipelineEvents *bool `url:"pipeline_events,omitempty" json:"pipeline_events,omitempty"`
WikiPageEvents *bool `url:"wiki_page_events,omitempty" json:"wiki_page_events,omitempty"`
EnableSSLVerification *bool `url:"enable_ssl_verification,omitempty" json:"enable_ssl_verification,omitempty"`
Token *string `url:"token,omitempty" json:"token,omitempty"`
}
type EditProjectHookOptions struct {
URL *string `url:"url,omitempty" json:"url,omitempty"`
PushEvents *bool `url:"push_events,omitempty" json:"push_events,omitempty"`
IssuesEvents *bool `url:"issues_events,omitempty" json:"issues_events,omitempty"`
MergeRequestsEvents *bool `url:"merge_requests_events,omitempty" json:"merge_requests_events,omitempty"`
TagPushEvents *bool `url:"tag_push_events,omitempty" json:"tag_push_events,omitempty"`
NoteEvents *bool `url:"note_events,omitempty" json:"note_events,omitempty"`
BuildEvents *bool `url:"build_events,omitempty" json:"build_events,omitempty"`
PipelineEvents *bool `url:"pipeline_events,omitempty" json:"pipeline_events,omitempty"`
WikiPageEvents *bool `url:"wiki_page_events,omitempty" json:"wiki_page_events,omitempty"`
EnableSSLVerification *bool `url:"enable_ssl_verification,omitempty" json:"enable_ssl_verification,omitempty"`
Token *string `url:"token,omitempty" json:"token,omitempty"`
}
According to the API docs, the response does not include the token so I don't think there is a need to add this field to the ProjectHook
type.
I would really reconsider the decision about converting options to pointers. It's not a common way.
But please, follow the Semver scheme. This was backward-incompatible change, but only minor part of the version number changed. My glide update
just broke the CI pipeline :D
I meant this commit: 4f1f8d2.
Cannot post project to specified namespace b/c NamespaceID is typed as *string, but it works if changed to *int in CreateProjectOptions struct
The commit data from events is a little different from other commit data from API
This is the commit data from PushEvent:
{
"id": "da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"message": "fixed readme",
"timestamp": "2012-01-03T23:36:29+02:00",
"url": "http://example.com/mike/diaspora/commit/da1560886d4f094c3e6c9ef40349f7d38b5d27d7",
"author": {
"name": "GitLab dev user",
"email": "gitlabdev@dv6700.(none)"
},
"added": ["CHANGELOG"],
"modified": ["app/controller/application.rb"],
"removed": []
}
And this json is used in other events like:
https://github.com/xanzy/go-gitlab/blob/master/events_test.go#L151
https://github.com/xanzy/go-gitlab/blob/master/events_test.go#L240
Can we use this data in the Commit struct or create another struct?
I'm sorry but I can't seem to find how to handle pagination. I see the ListOptions
type but for example I can't use it for ListAllProjects()
. Maybe I'm missing something.
Hi, is there support for pipelines api
https://docs.gitlab.com/ce/api/pipelines.html
Thanks
When parsing gitlab pipeline event hook giving pipeline json unmarshal error. https://docs.gitlab.com/ce/web_hooks/web_hooks.html#pipeline-events
Failed to build the application: ../github.com/xanzy/go-gitlab/gitlab.go:21:2: cannot find package "context" in any of:
/Users/apple/golang/src/github.com/xanzy/go-gitlab/vendor/context (vendor tree)
/usr/local/go/src/context (from $GOROOT)
/Users/apple/golang/src/context (from $GOPATH)
Hello!
I am trying to list commits by merge request (https://docs.gitlab.com/ce/api/merge_requests.html#get-single-mr-commits). I can't find anywhere in the docs how to do this so I am wondering if this is supported?
Thanks!
Hi, it seem that go-gitlab only support for private_token
, no support for OAuth2 token. Has any plan to change it?
Hi,
My go version is: go1.7.4 darwin/amd64
I'm unable to use the Repositories.Archive()
method without having an error about stream:
stream error: stream ID 1; PROTOCOL_ERROR
.
I must add that i didn't have the problem like 2 months ago (since then, i have updated dependencies and go bin)
When i'm doing the call to gitlab api using postman and the same token, i don't have any errors.
i dont know if the problem is from this package, golang or ... ?
Here is the go code (hash = 0.6.0
and projectNamespaceOrId = 365
):
opt := &gitlabApi.ArchiveOptions{SHA: &hash}
bites, _, err := gitlab.Client.Repositories.Archive(projectNamespaceOrId, opt)
And here is a screen when using postman:
https://cl.ly/0g3q0F3P1Q07
Here is the nginx log when calling repository using go:
https://cl.ly/0J412s3F1Q0l
I don't have this error for any other calls that are made by the package, so i really don't know what's the problem.
Help would be appreciate
The package name is gitlab
while the repo name is go-gitlab
. This works, but results in confusing usage:
import (
"github.com/xanzy/go-gitlab"
)
func foo() {
git := gitlab.NewClient(nil, "yourtokengoeshere")
}
Where is gitlab
being declared or imported? This is an extreme case, but if all packages did this, complex programs would be a mess. You could go around this as a user by explicitly importing gitlab "github.com/xanzy/go-gitlab"
, but that's really unnecessary.
Moreover, the Go authors discourage calling packages or programs go-*
simply because they are written in Go. You may think that calling your repo gitlab
might confuse people with the GitLab reo itself, but it's easy to tell apart since one is a Ruby app and another a Go package.
I am trying to delete an issue for a project for which I am the owner. I am using my private token in the client.
However I am getting the following output
DELETE https://gitlab.com/api/v3/projects/shank/gitlab/issues/8: 403 403 Forbidden []
All other commands (like getting list of issues for a project, creating an issue etc.) are working.
Since this is a private project, I am sharing the screenshot below of the list of issues.
Right now, the API can not be used with http://gopkg.in because the version is still 0.5.
What do you think about releasing api v3 support as 1.0?
Then when the upgrade to v4 is finished you could bump the version to 2.0.
(An alternative would be to have the major version track the gitlab api version, but that would mean no breaking changes ever for one API version which is maybe not ideal).
Currently only a couple of the following services are supported:
Drone CI
Hipchat
Slack Notifications
Furthermore, only Drone CI has the getter defined, and there's also definitions for a Gitlab CI service which does not seem to exist anymore (using https://docs.gitlab.com/ce/api/services.html as a reference).
The Issue
struct (and the parsing stuff etc.) does not have the web_url
field.
Would you be willing to accept a PR in case, I make the necessary changes to add the same?
With the context
being made part of the standard library in 1.7, it should be possible to use a context
for tracking requests, maybe at a client level and/or at a specific request level. Perhaps it could be an Option (WithContext
)? The context should be used with the http.Client
when performing requests, like so:
resp, err := client.Do(req.WithContext(ctx))
https://github.com/golang/net/blob/master/context/ctxhttp/ctxhttp.go is a nice example of how this is done.
EDIT: I just had a look at the gitlab.OptionFunc
and this seems almost serendipitously well suited for something like this:
// WithContext runs the request with the provided context
func WithContext(ctx context.Context) OptionFunc {
return func(req *http.Request) error {
req = req.WithContext(ctx)
return nil
}
}
}
I just tried to use GetIssue
to fetch information on an issue on a project of mine. To my surprise, it gave a 404.
Digging through the gitlab api docs, I found out that in /projects/:id/issues/:issue_id
, :issue_id
is global, and not local.
Hence, GetIssue
is of very little use. I had to use ListProjectIssues
with &client.ListProjectIssuesOptions{IID: n}
for it to work.
I'm not saying this is an issue on your end - this very much looks like a bug or a misfeature on their API. We should ask them about it, and add a comment on methods like GetIssue
that suffer from this if they are not going to fix it.
In Gitlab 8.12, the notification settings feature was introduced, allowing a user to set email notification preferences globally or at project/group level.
Are there any immediate plans or work in progress to add this functionality to go-gitlab
? If not I will be happy to contribute.
There's a typo in the JSON hint for CreateProjectOptions.BuildsEnabled
:
json:"build_events,omitempty"
json:"builds_enabled,omitempty"
See https://github.com/xanzy/go-gitlab/blob/master/projects.go#L346
Hi, I am writing code for gitlab Push Hook event.
When I am Unmarshal the gitlab's example https://docs.gitlab.com/ce/web_hooks/web_hooks.html#push-events
But I have a problem with json unmarshal.
The output
json: cannot unmarshal string into Go value of type gitlab.ProjectNamespace
jsonBlob is gitlab's example json.
var e gitlab.PushEvent
unmarshalErr := json.Unmarshal(jsonBlob, &e)
Could you help me?
It's currently defined as such:
// AddDeployKeyOptions represents the available ADDDeployKey() options.
//
// GitLab API docs:
// https://docs.gitlab.com/ce/api/deploy_keys.html#add-deploy-key
type AddDeployKeyOptions struct {
Title *string `url:"title,omitempty" json:"title,omitempty"`
Key *string `url:"key,omitempty" json:"key,omitempty"`
}
However, according to the API docs there is another variable, can_push
which is not currently exposed by the library.
Do you plan on adding projects/<id>/{builds,repository}
API?
http://doc.gitlab.com/ce/api/builds.html
Seeing this when unmarhsaling a webhook into IssueEvent
:
json: cannot unmarshal string into Go struct field Project.namespace of type gitlab.ProjectNamespace
I think the package would profit from tests against a real API. It could be organized as follows:
Doesn't look like project pipeline triggers are supported yet?
I'm having trouble with the boolean options in gitlab.CreateProjectOptions
, GitLab seems to ignore them:
gitlab.CreateProjectOptions
looks ok.Maybe I'm doing something wrong, hence my hope that someone more knowledgeable can provide insight. Any hints are greatly appreciated!
Tested with go-gitlab 81953bb and GitLab 8.13.0 and 8.12.x.
&gitlab.CreateProjectOptions{
Name: gitlab.String("foo"),
Description: gitlab.String("Lorem ipsum dolor sit amet."),
IssuesEnabled: gitlab.Bool(true),
MergeRequestsEnabled: gitlab.Bool(true),
BuildsEnabled: gitlab.Bool(true),
WikiEnabled: gitlab.Bool(true),
SnippetsEnabled: gitlab.Bool(true),
SharedRunnersEnabled: gitlab.Bool(true),
Public: gitlab.Bool(false),
VisibilityLevel: gitlab.VisibilityLevel(gitlab.PrivateVisibility),
PublicBuilds: gitlab.Bool(false),
OnlyAllowMergeIfBuildSucceeds: gitlab.Bool(false),
LFSEnabled: gitlab.Bool(true),
RequestAccessEnabled: gitlab.Bool(false),
}
{
"name": "foo",
"description": "Lorem ipsum dolor sit amet.",
"issues_enabled": true,
"merge_requests_enabled": true,
"builds_enabled": true,
"wiki_enabled": true,
"snippets_enabled": true,
"shared_runners_enabled": true,
"public": false,
"visibility_level": 0,
"public_builds": false,
"only_allow_merge_if_build_succeeds": false,
"lfs_enabled": true,
"request_access_enabled": false
}
{
"container_registry_enabled": false,
"issues_enabled": false,
"merge_requests_enabled": false,
"wiki_enabled": false,
"builds_enabled": false,
"snippets_enabled": false,
"shared_runners_enabled": true,
"lfs_enabled": true,
"public_builds": false,
"only_allow_merge_if_build_succeeds": false,
"request_access_enabled": false
}
package main
import (
"crypto/tls"
"fmt"
"log"
"math/rand"
"net/http"
"net/http/httputil"
"os"
"strconv"
"time"
httplogger "github.com/ernesto-jimenez/httplogger"
gitlab "github.com/xanzy/go-gitlab"
)
var (
gitlabURL = "https://gitlab.example.com/api/v3"
gitlabToken = "eeghupha5po5zuD0dool"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
func main() {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
logTr := httplogger.NewLoggedTransport(tr, newHTTPLogger())
glc := gitlab.NewClient(&http.Client{Transport: logTr}, gitlabToken)
glc.SetBaseURL(gitlabURL)
opt := &gitlab.CreateProjectOptions{
Name: gitlab.String("foo-" + strconv.Itoa(rand.Int())),
Description: gitlab.String("Lorem ipsum dolor sit amet."),
IssuesEnabled: gitlab.Bool(true),
MergeRequestsEnabled: gitlab.Bool(true),
BuildsEnabled: gitlab.Bool(true),
WikiEnabled: gitlab.Bool(true),
SnippetsEnabled: gitlab.Bool(true),
SharedRunnersEnabled: gitlab.Bool(true),
Public: gitlab.Bool(false),
VisibilityLevel: gitlab.VisibilityLevel(gitlab.PrivateVisibility),
PublicBuilds: gitlab.Bool(false),
OnlyAllowMergeIfBuildSucceeds: gitlab.Bool(false),
LFSEnabled: gitlab.Bool(true),
RequestAccessEnabled: gitlab.Bool(false),
// ContainerRegistryEnabled: gitlab.Bool(true),
}
prj, _, err := glc.Projects.CreateProject(opt)
if err != nil {
log.Fatal(err)
}
fmt.Println("IssuesEnabled .......... expected:", *opt.IssuesEnabled, "- actual:", prj.IssuesEnabled)
fmt.Println("MergeRequestsEnabled ... expected:", *opt.MergeRequestsEnabled, "- actual:", prj.MergeRequestsEnabled)
fmt.Println("BuildsEnabled .......... expected:", *opt.BuildsEnabled, "- actual:", prj.BuildsEnabled)
fmt.Println("WikiEnabled ............ expected:", *opt.WikiEnabled, "- actual:", prj.WikiEnabled)
fmt.Println("SnippetsEnabled ........ expected:", *opt.SnippetsEnabled, "- actual:", prj.SnippetsEnabled)
fmt.Println("SharedRunnersEnabled ... expected:", *opt.SharedRunnersEnabled, "- actual:", prj.SharedRunnersEnabled)
// fmt.Println("LFSEnabled .......... expected:", *opt.LFSEnabled, "- actual:", prj.LFSEnabled)
}
type httpLogger struct {
log *log.Logger
}
func newHTTPLogger() *httpLogger {
return &httpLogger{
log: log.New(os.Stderr, "[DEBUG] ", log.LstdFlags),
}
}
func (l *httpLogger) LogRequest(req *http.Request) {
dump, err := httputil.DumpRequestOut(req, true)
if err != nil {
log.Fatal(err)
}
l.log.Printf("HTTP Request follows...\n%s\n---", string(dump))
}
func (l *httpLogger) LogResponse(req *http.Request, res *http.Response, err error, duration time.Duration) {
dump, err := httputil.DumpResponse(res, true)
if err != nil {
log.Fatal(err)
}
l.log.Printf("HTTP Response follows...\n%s\n---", string(dump))
}
Looks like when submitting boolean parameters, only the true parameters get sent, and the false ones get skipped.
p := &gitlab.EditProjectOptions{
IssuesEnabled: false,
MergeRequestsEnabled: false,
WikiEnabled: true,
SnippetsEnabled: false,
VisibilityLevel: gitlab.InternalVisibility,
}
gl.Projects.EditProject(*project.ID, p)
I added some logging to the marshalling step:
&gitlab.EditProjectOptions{Name:"", Path:"", Description:"", DefaultBranch:"", IssuesEnabled:false, MergeRequestsEnabled:false, WikiEnabled:true, SnippetsEnabled:false, Public:false, VisibilityLevel:10}
"{\"wiki_enabled\":true,\"visibility_level\":10}"
I think it's hitting this issue: golang/go#13284
The readme explains it covers 100% of the gitlab v3 api. However I cannot find some of the integrated CI-calls. For example get the status of a commit or posting the status of a commit. Is this by design or did it not yet get implemented after the gitlab was merged with CI?
Check out this.
If I need to set up a project for the private, because used omitempty VisibilityLevel EditProjectOptions tag, so ignore 0. So can not set the project for the private
Ps:EditProjectOptions in the Public is the time is false
Currently, BuildsService.ListProjectBuilds()
will only return the 20 most recent builds.
The GitLab API documentation doesn't indicate which endpoints use pagination and which ones do not, but I've experimentally determined that GET /projects/:id/builds
indeed does use pagination, and supports page
and per_page
.
In go-gitlab
, the ProjectsService.ListProjects()
API for example, takes a ListProjectsOptions
argument, which embeds a ListOptions
struct which handles the pagination. ListBuildsOptions
on the other hand does not embed ListOptions
.
Is there a way to upload an attachment? I can see Note.Attachment
in the library doc, but no related method to upload a file and reference it in a note for example.
GitLab has an API endpoint for that: http://doc.gitlab.com/ce/api/projects.html#uploads
If not, I can add support for it as a method of ProjectsService
.
Permissions attribute is not supported
http://doc.gitlab.com/ce/api/projects.html#get-single-project
In the api docs for getting a single project, under the JSON returned for the project, there is a field shared_with_groups
. I wish to add support for this to the library.
Is it ok if I send a pull request with the required changes?
Could you please setup some code coverage tool e.g. https://coveralls.io to see code coverage status?
Coveralls.io is free for open source projects.
I discovered a possible bug today related to how the client handles validation errors returned from the API. According to the docs, validation errors will be formatted as following in the response:
HTTP/1.1 400 Bad Request
Content-Type: application/json
{
"message": {
"bio": [
"is too long (maximum is 255 characters)"
]
}
}
{
"message": {
"<property-name>": [
"<error-message>",
"<error-message>",
...
],
"<embed-entity>": {
"<property-name>": [
"<error-message>",
"<error-message>",
...
],
}
}
}
In the code, an error response body is always unmarshalled into a ErrorResponse
struct:
type ErrorResponse struct {
Response *http.Response // HTTP response that caused this error
Message string `json:"message"` // error message
Errors []Error `json:"errors"` // more detail on individual errors
}
This fails because the struct does not correctly reflect the response, resulting in an empty ErrorResponse
being returned.
I have no experience with the older versions of the Gitlab API, so don't know if the error response format has changed, or whether this always has been a bug.
If the user never connected, the field "current_sign_in_at" is null and break json decoding.
{
"name":"Foo Bar",
"username":"foobar",
"id":5,
"state":"blocked",
"avatar_url":null,
"web_url":"http://exemple/u/foobar",
"created_at":"2014-07-28T09:45:22.557Z",
"is_admin":false,
"bio":null,
"skype":"",
"linkedin":"",
"twitter":"",
"website_url":"",
"email":"foobar@exemple",
"theme_id":2,
"color_scheme_id":1,
"projects_limit":10,
"current_sign_in_at":null,
"identities":{
},
"can_create_group":false,
"can_create_project":true,
"two_factor_enabled":false
}
This might be something people more used to REST wrappers know, but for me the Response docs are incomplete. What is the behaviour of NextPage
? Should I assume there's more data if NextPage
is not zero?
Also the GitLab pagination docs indicate there's also X-Page
and X-Total-Pages
headers sent back. Would it be helpful to include them?
I note that the GitHub API does not have such fields so perhaps you're trying to stay similar to theirs?
If not, might it be an idea to make iterators that hide the pagination?
I can' find method to list group' projects (https://docs.gitlab.com/ce/api/groups.html#list-a-group-s-projects) is this implemented ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.