Git Product home page Git Product logo

go-gitlab's People

Contributors

ahuret avatar alex1989hu avatar alexkalderimis avatar ax1036 avatar cmmarslender avatar falcosuessgott avatar fantasyteddy avatar gaikwadpratik avatar heidiberry avatar itscaro avatar justinrush avatar klmitch avatar kordianbruck avatar lorac avatar martinsefcik avatar mauamy avatar mgross-ebner avatar michaellihs avatar patrickrice-ksc avatar pmwebster avatar pschwartz avatar sirlatrom avatar smit-modi avatar svanharmelen avatar theoriginalstove avatar timofurrer avatar urento avatar venky333 avatar vntw avatar zaquestion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-gitlab's Issues

What is Context?

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)

How to create an issue?

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?

Uploading a file

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.

Add `web_url` field to `Issue`

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?

Support for gopkg.in / Release 1.0

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).

I don't think we should use omitempty

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

Rename repo to xanzy/gitlab

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.

How to handle pagination?

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.

Merge request work_in_progress

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 👻

Semver scheme

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.

Make all HTTP calls context-aware

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
		}
	}
}

Inconsistencies in naming

e.g. ListMergeRequests and ListProjectIssues, when they both work with projects. Either make both have Project, or neither.

Cannot get issue/MR by internal ID

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.

Support all Services

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).

[/users] current_sign_in_at is null...

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
}

Unable to delete issue using `&gitlab.Issues.DeleteIssue(pid, issue_id)`. Getting 403 forbidden

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.
list of issues

Structs should use pointers for fields

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 ?

Token field is missing from AddProjectHookOptions

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.

Commit sctruct on events

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?

Issue event struct out of date?

Seeing this when unmarhsaling a webhook into IssueEvent:

json: cannot unmarshal string into Go struct field Project.namespace of type gitlab.ProjectNamespace

Support the v4 API

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.

Completed

  • Rename Build Triggers to be Pipeline Triggers API !9713. Fixed in #152.
    • POST /projects/:id/trigger/builds to POST /projects/:id/trigger/pipeline
    • Require description when creating a new trigger POST /projects/:id/triggers
  • Removed 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.
  • Endpoints under GET /projects/merge_request/:id have been removed (use: GET /projects/merge_requests/:id) !8793. Fixed in #161.
  • Project snippets do not return deprecated field expires_at !8723. Fixed in #161.
  • Endpoints under GET /projects/:id/keys have been removed (use GET /projects/:id/deploy_keys) !8716. Fixed in #161.
  • Update v3 documentation to point to archived v3 docs. Fixed in #160.
  • Return basic info about pipeline in GET /projects/:id/pipelines !8875. Fixed in #163
  • Renamed all build references to job !9463. Fixed in #166.
  • Use visibility as string parameter everywhere !9337. Fixed in #167.
  • Project filters are no longer available as 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 authorization
    • GET /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.
    • To get projects the user is a member of, use GET /projects?membership=true
  • Return HTTP status code 400 for all validation errors when creating or updating a member instead of sometimes 422 error. !9523. Doesn't require changes.
  • Status 409 returned for POST /projects/:id/members when a member already exists !9093. Doesn't require changes.
  • Remove GET /groups/owned. Use GET /groups?owned=true instead !9505. Fixed in commit 62634b8.
  • Moved POST /projects/fork/:id to POST /projects/:id/fork !8940. Fixed in commit 577e19d.
  • Renamed the 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
  • Update endpoints for repository files !9637. Fixed in commit a0b1dcb.
    • Moved 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
    • Moved 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
  • Removed the following deprecated Templates endpoints (these are still accessible with /templates prefix) !8853
    • /licences
    • /licences/:key
    • /gitignores
    • /gitlab_ci_ymls
    • /dockerfiles
    • /gitignores/:key
    • /gitlab_ci_ymls/:key
    • /dockerfiles/:key
  • Moved DELETE /todos to POST /todos/mark_as_done and DELETE /todos/:todo_id to POST /todos/:todo_id/mark_as_done !9410
  • Return pagination headers for all endpoints that return an array !8606
  • Removed DELETE /projects/:id/deploy_keys/:key_id/disable. Use DELETE /projects/:id/deploy_keys/:key_id instead !9366
  • Moved PUT /users/:id/(block|unblock) to POST /users/:id/(block|unblock) !9371
  • Make subscription API more RESTful. Use POST /projects/:id/:subscribable_type/:subscribable_id/subscribe to subscribe and POST /projects/:id/:subscribable_type/:subscribable_id/unsubscribe to unsubscribe from a resource. !9325
  • Labels filter on GET /projects/:id/issues and GET /issues now matches only issues containing all labels (i.e.: Logical AND, not OR) !8849
  • Renamed param branch_name to branch on the following endpoints !8936
    • POST /projects/:id/repository/branches
    • POST /projects/:id/repository/commits
    • POST/PUT/DELETE :id/repository/files
  • Renamed branch_name to branch on DELETE /projects/:id/repository/branches/:branch response !8936
  • Remove public param from create and edit actions of projects !8736
  • Remove subscribed field from responses returning list of issues or merge
    requests. Fetch individual issues or merge requests to obtain the value
    of subscribed
    !9661
  • Notes do not return deprecated field upvote and downvote !9384
  • Return 202 with JSON body on async removals on V4 API (DELETE /projects/:id/repository/merged_branches and DELETE /projects/:id) !9449
  • GET /projects/:id/milestones?iid[]=x&iid[]=y array filter has been renamed to iids !9096
  • Drop GET /projects/:id/repository/commits/:sha/jobs !9463
  • Simplify project payload exposed on Environment endpoints !9675
  • API uses merge request IIDs (internal ID, as in the web UI) rather than IDs. This affects the merge requests, award emoji, todos, and time tracking APIs. !9530
  • API uses issue IIDs (internal ID, as in the web UI) rather than IDs. This affects the issues, award emoji, todos, and time tracking APIs. !9530
  • Change initial page from 0 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)
  • Return correct Link header data for GET /projects/:id/repository/commits [!9679] (https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/9679)

Incorrect handling of API errors

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.

Test against gitlab.com

I think the package would profit from tests against a real API. It could be organized as follows:

  • create an account just for testing
  • setup tests
  • insert the secret key of the testing account into the tests via ENV from eg coveralls #21
  • insert the coverage badge into the README

AddDeployKeyOptions does not contain all API options

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.

Pagination

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?

Support pagination in BuildsService.ListProjectBuilds

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.

Notification settings API

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.

The GroupMember.AccessLevel field should be of AccessLevel type

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

Pipelines API

Hi, is there support for pipelines api

https://docs.gitlab.com/ce/api/pipelines.html

Thanks

false values for EditProject don't get submitted

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

Problem with Repositories.Archive() [STREAM error]

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

GitLab ignores boolean options in gitlab.CreateProjectOptions

I'm having trouble with the boolean options in gitlab.CreateProjectOptions, GitLab seems to ignore them:

  • Call to gitlab.CreateProjectOptions looks ok.
  • Generated JSON request looks ok.
  • GitLab creates the project, yet ignores the boolean options and applies what seem to be defaults.

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.

Details

Project Options

&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),
}

JSON Request

{
  "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
}

JSON Response (excerpt)

{
  "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
}

Full Test Case

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))
}

Group Merge Request WebHook

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.

json: cannot unmarshal

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?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.