Commit 8f10c231 authored by Etienne Baqué's avatar Etienne Baqué
Browse files

Updated codebase based on review comments

parent e294f572
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -152,11 +152,11 @@ func TestApp(t *testing.T) {
			args:       []string{"get"},
			wantErrStr: "Required flag \"tag-name\" not set",
		},
		"success_with_release_file": {
			res:            testdata.ResponseCreateReleaseSuccess,
			args:           []string{"create", "--file", "testdata/release.txt"},
			wantLogEntries: []string{"Creating Release...", "release created successfully!"},
		},
		// "success_with_release_file": {
		// 	res:            testdata.ResponseCreateReleaseSuccess,
		// 	args:           []string{"create", "--file", "testdata/release.yml"},
		// 	wantLogEntries: []string{"Creating Release...", "release created successfully!"},
		// },
	}

	for tn, tt := range tests {
+3 −58
Original line number Diff line number Diff line
@@ -37,50 +37,6 @@ func Create(log logrus.FieldLogger, httpClientFn httpClientFn) *cli.Command {
		},
		Before:      createFlags.BeforeHook(flagList),
		Subcommands: nil,
		Flags: []cli.Flag{
			&cli.StringFlag{
				Name:     flags.TagName,
				Usage:    "(required) The tag the release will be created from",
				Required: true,
				EnvVars:  []string{"CI_COMMIT_TAG"},
			},
			&cli.StringFlag{
				Name:     flags.Name,
				Usage:    "The release name",
				Required: false,
			},
			&cli.StringFlag{
				Name:     flags.Description,
				Usage:    "The description of the release; you can use Markdown. A file can be used to read the description contents, must exist inside the working directory; if it contains any whitespace, it will be treated as a string",
				Required: false,
			},
			&cli.StringFlag{
				Name:     flags.TagMessage,
				Usage:    "Message to use if creating a new annotated tag",
				Required: false,
			},
			&cli.StringFlag{
				Name:     flags.Ref,
				Usage:    "If tag_name doesn’t exist, the release will be created from ref; it can be a commit SHA, another tag name, or a branch name",
				Required: false,
				EnvVars:  []string{"CI_COMMIT_SHA"},
			},
			&cli.StringSliceFlag{
				Name:     flags.AssetsLink,
				Usage:    `JSON string representation of an asset link; (e.g. --assets-link='{"name": "Asset1", "url":"https://<domain>/some/location/1", "link_type": "other", "filepath": "xzy" }' or --assets-link='[{"name": "Asset1", "url":"https://example.com/some/location/1"}, {"name": "Asset2", "url":"https://example.com/some/location/2"}]'`,
				Required: false,
			},
			&cli.StringSliceFlag{
				Name:     flags.Milestone,
				Usage:    `List of the titles of each milestone the release is associated with (e.g. --milestone "v1.0" --milestone "v1.0-rc)"; each milestone needs to exist `,
				Required: false,
			},
			&cli.StringFlag{
				Name:     flags.ReleasedAt,
				Usage:    `The date when the release will be/was ready; defaults to the current time; expected in ISO 8601 format (2019-03-15T08:00:00Z)`,
				Required: false,
			},
		},
		Flags:       flagList,
	}
}
@@ -261,22 +217,11 @@ func printAllAssetsAsJSON(w io.Writer, release *gitlab.ReleaseResponse, logger l
}

func initCreateFlags() flags.PassedInFlags {
	var flagsToUse flags.PassedInFlags

	hasFileOption := false

	for _, a := range os.Args[1:] {
		if a == "--file" {
			hasFileOption = true
			break
		}
			return flags.FileFlag{}
		}

	if hasFileOption {
		flagsToUse = flags.FileFlag{}
	} else {
		flagsToUse = flags.ParameterFlag{}
	}

	return flagsToUse
	return flags.ParameterFlag{}
}
+3 −3
Original line number Diff line number Diff line
@@ -29,9 +29,9 @@ func (FileFlag) BeforeHook(flags []cli.Flag) cli.BeforeFunc {
// ListFlags implementation for ParameterFlag.
func (ParameterFlag) ListFlags() *[]cli.Flag {
	return &[]cli.Flag{
		tagNameFlag(true),
		nameFlag(),
		descriptionFlag(),
		tagNameFlag(true),
		tagMessageFlag(),
		refFlag(),
		assetsLinkFlag(),
@@ -43,9 +43,9 @@ func (ParameterFlag) ListFlags() *[]cli.Flag {
// ListFlags implementation for FileFlag.
func (FileFlag) ListFlags() *[]cli.Flag {
	return &[]cli.Flag{
		altsrc.NewStringFlag(tagNameFlag(false)),
		altsrc.NewStringFlag(nameFlag()),
		altsrc.NewStringFlag(descriptionFlag()),
		altsrc.NewStringFlag(tagNameFlag(false)),
		altsrc.NewStringFlag(tagMessageFlag()),
		altsrc.NewStringFlag(refFlag()),
		altsrc.NewStringSliceFlag(assetsLinkFlag()),
@@ -78,7 +78,7 @@ func descriptionFlag() *cli.StringFlag {
func tagNameFlag(required bool) *cli.StringFlag {
	return &cli.StringFlag{
		Name:     TagName,
		Usage:    "The tag the release will be created from",
		Usage:    "(required) The tag the release will be created from",
		Required: required,
		EnvVars:  []string{"CI_COMMIT_TAG"},
	}
+13 −0
Original line number Diff line number Diff line
@@ -2,8 +2,21 @@
name: Release for test
description: This is a release for testing only.
tag-name: v1.2.3
released_at: 2019-01-03T01:55:18.203Z
ref: abcdefgh12345678
milestones:
  - title: milestone1
    project_id: 1
    state: active
  - title: milestone2
    project_id: 2
    state: active
assets-link:
  - name: asset1
    url: https://gitlab.com/gitlab-org/release-cli
    type: other
    filepath: xyz
  - name: asset2
    url: https://gitlab.com
    type: other
    filepath: abc