Skip to content
This repository has been archived by the owner on Nov 22, 2022. It is now read-only.

feat: add new release commands to manage GitLab releases #445

Merged
merged 15 commits into from
May 27, 2021
Next Next commit
feat: add release create command
  • Loading branch information
profclems committed May 22, 2021
commit c707d7d3f7481a2392ddb9de8fdf0f9303d878b7
31 changes: 31 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ workflow:
- if: '$CI_COMMIT_BRANCH =~ /^[\d-]+-stable$/'
#

stages:
- test

default:
image: golang:1.15

Expand All @@ -37,3 +40,31 @@ code_navigation:
artifacts:
reports:
lsif: dump.lsif

.test:
variables:
GOPATH: "/builds/go"
GIT_CLONE_PATH: $GOPATH/src/github.com/profclems/glab
GITLAB_TOKEN: "qRC87Xg9Wd46RhB8J8sp"
CODECOV_TOKEN: "1597edbc-8760-42c1-ab79-c192ad151717"
before_script:
# Add a non-sensitive ssh key for test to work.
- mkdir ~/.ssh && chmod 700 ~/.ssh
- echo -e "Host *\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
- echo -e "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCc54ULcDSmuQBMaM52dqxNMETAlwn01AF79vJb6Nw3SzkNKEMY1pBttM1U8wz7dHpVteAQGCU2AH+T2UhswZWPIzcMfVwB+1RgcIkHW184V5FX1xxqo4Xx6CC6LTSq3md/EmXfQR7gAwaKQHy6txxYpEprlhw+EWICgD5znUMprRRbcsb2FoAdsodMWSl5aRIyC1rA06SKKwqN09o4mgNhv49McyzDnUCGmSTc0oQpygPadDRqW46iCkMdiJa1fuP9pSGkAuTaQayILbDenAM3cV7LqsIm7tOXLPW5fQm9FB91ftRLXxk1Mp6lMYqNc5eGoR4ATzHn7M/VHbBaqVlp profclems@ProfClems" > ~/.ssh/id_rsa.pub
- echo -e "-----BEGIN OPENSSH PRIVATE KEY-----\nb3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABFwAAAAdzc2g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/\n4htjlAxdz2Zxa8JL437s56Jf4ZtDOYt367dhTMRBleoxAAAAgDo0de+4nNSVb/H3aGo5Y0\nLg/q/npYUNVSvZ9R0GfRY0qDbNCaKeqbyJDkReRn5R/KKT9+Gx0/zqXGNi1ubnGtxqCCmC\nYHDys0PSw6yAEDZ3JOeYWEIO7ntH0DKdErcEUj+FqatdIpoZZO48XZDSXzO1+B1n2y+AML\nfyMggdFXIBAAAAgQDMnIFss9kLpnqC5QOAiDO+jsnHwNHENBgQKE9/jM6gagaK3T4TDkJl\nPszXRDE11LSBCxahL5rxwWDog1vG67tnbfznjhGm8Fd+mEs6omuQ5pA0o6Qx40xtkfn3vi\nj4NLkpo5rYg0DTtciDgGeibtt1oT1EhKZ59ystGdFgSGWxtQAAAIEAxE+xPCLHzqEUUlxI\nSJC6+e2hUT/9s64OwmH9pCrQ8+96G9TtbR9NFD1LSArnLXvl6ooYODw0QDjLdgCUQj63r7\nqOV9QjWKL6xD1atN37WFbrIpem8pFOJWinYrQtddANSBd5tp5QsDkI58ovqhdDuYoVfL1y\nmEfWvucOVlZraWUAAAATcHJvZmNsZW1zQFByb2ZDbGVtcw==\n-----END OPENSSH PRIVATE KEY-----" > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa*
- eval `ssh-agent -s`
- ssh-add ~/.ssh/id_rsa
script:
- go version
- export PATH=$GOPATH/bin:$PATH
- go get -t -v ./...
- make test
after_script:
- bash <(curl -s https://codecov.io/bash)

test:
stage: test
extends: .test
image: golang:1.15
14 changes: 14 additions & 0 deletions api/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ package api

import "github.com/xanzy/go-gitlab"

var CreateRelease = func(client *gitlab.Client, projectID interface{}, opts *gitlab.CreateReleaseOptions) (*gitlab.Release, error) {
if client == nil {
client = apiClient.Lab()
}

release, _, err := client.Releases.CreateRelease(projectID, opts)
if err != nil {
return nil, err
}

return release, nil
}

var GetRelease = func(client *gitlab.Client, projectID interface{}, tag string) (*gitlab.Release, error) {
if client == nil {
client = apiClient.Lab()
Expand All @@ -14,6 +27,7 @@ var GetRelease = func(client *gitlab.Client, projectID interface{}, tag string)

return release, nil
}

var ListReleases = func(client *gitlab.Client, projectID interface{}, opts *gitlab.ListReleasesOptions) ([]*gitlab.Release, error) {
if client == nil {
client = apiClient.Lab()
Expand Down
19 changes: 18 additions & 1 deletion commands/cmdutils/errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package cmdutils

import "errors"
import (
"errors"

"github.com/spf13/cobra"
)

// FlagError is the kind of error raised in flag processing
type FlagError struct {
Expand All @@ -17,3 +21,16 @@ func (fe FlagError) Unwrap() error {

// SilentError is an error that triggers exit code 1 without any error messaging
var SilentError = errors.New("SilentError")

func MinimumArgs(n int, msg string) cobra.PositionalArgs {
if msg == "" {
return cobra.MinimumNArgs(1)
}

return func(cmd *cobra.Command, args []string) error {
if len(args) < n {
return &FlagError{Err: errors.New(msg)}
}
return nil
}
}
Loading