gitlab.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /*
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. package gitlab
  13. import (
  14. "log"
  15. "os"
  16. gitlab "github.com/xanzy/go-gitlab"
  17. )
  18. // Requires a token to be set in environment variable
  19. var GITLABTOKEN = os.Getenv("GITLABTOKEN")
  20. type GitlabCredentials struct {
  21. Token string `json:"token"`
  22. }
  23. // Gitlab struct with values for *gitlab.Client and projectID
  24. type Gitlab struct {
  25. client *gitlab.Client
  26. projectID interface{}
  27. }
  28. // Function newGitlabProvider returns a reference to a new Gitlab struct 'instance'
  29. func NewGitlabProvider() *Gitlab {
  30. return &Gitlab{}
  31. }
  32. // Method on Gitlab to set up client with credentials and populate projectID
  33. func (g *Gitlab) NewGitlabClient(cred GitlabCredentials, projectID int) {
  34. var err error
  35. // Create a new Gitlab client with credentials
  36. g.client, err = gitlab.NewClient(cred.Token, nil)
  37. g.projectID = projectID
  38. if err != nil {
  39. log.Fatalf("Failed to create client: %v", err)
  40. }
  41. }