Commit 58f24d18 authored by Jaime Martinez's avatar Jaime Martinez 🔴
Browse files

Merge branch...

Merge branch '165-use-direct_asset_path-instead-of-filepath-when-calling-releases-or-release-links-apis' into 'master'

Resolve "Use `direct_asset_path` instead of `filepath` when calling Releases or Release Links APIs"

Closes #165

See merge request !174



Merged-by: default avatarJaime Martinez <jmartinez@gitlab.com>
Approved-by: default avatarPedro Pombeiro <noreply@pedro.pombei.ro>
Approved-by: default avatarJaime Martinez <jmartinez@gitlab.com>
Reviewed-by: default avatarPedro Pombeiro <noreply@pedro.pombei.ro>
Co-authored-by: Timo Furrer's avatarTimo Furrer <tfurrer@gitlab.com>
parents 2e1309d5 51f98aef
Loading
Loading
Loading
Loading
Loading
+12 −12
Original line number Diff line number Diff line
@@ -18,37 +18,37 @@ release-from-tag:
      links:
        - name: 'darwin/amd64'
          url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-darwin-amd64"
          filepath: '/bin/release-cli-darwin-amd64'
          direct_asset_path: '/bin/release-cli-darwin-amd64'
        - name: 'darwin/arm64'
          url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-darwin-arm64"
          filepath: '/bin/release-cli-darwin-arm64'
          direct_asset_path: '/bin/release-cli-darwin-arm64'
        - name: 'freebsd/386'
          url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-freebsd-386"
          filepath: '/bin/release-cli-freebsd-386'
          direct_asset_path: '/bin/release-cli-freebsd-386'
        - name: 'freebsd/amd64'
          url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-freebsd-amd64"
          filepath: '/bin/release-cli-freebsd-amd64'
          direct_asset_path: '/bin/release-cli-freebsd-amd64'
        - name: 'freebsd/arm'
          url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-freebsd-arm"
          filepath: '/bin/release-cli-freebsd-arm'
          direct_asset_path: '/bin/release-cli-freebsd-arm'
        - name: 'linux/386'
          url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-linux-386"
          filepath: '/bin/release-cli-linux-386'
          direct_asset_path: '/bin/release-cli-linux-386'
        - name: 'linux/amd64'
          url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-linux-amd64"
          filepath: '/bin/release-cli-linux-amd64'
          direct_asset_path: '/bin/release-cli-linux-amd64'
        - name: 'linux/arm'
          url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-linux-arm"
          filepath: '/bin/release-cli-linux-arm'
          direct_asset_path: '/bin/release-cli-linux-arm'
        - name: 'linux/arm64'
          url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-linux-arm64"
          filepath: '/bin/release-cli-linux-arm64'
          direct_asset_path: '/bin/release-cli-linux-arm64'
        - name: 'linux/ppc64le'
          url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-linux-ppc64le"
          filepath: '/bin/release-cli-linux-ppc64le'
          direct_asset_path: '/bin/release-cli-linux-ppc64le'
        - name: 'windows/386'
          url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-windows-386.exe"
          filepath: '/bin/release-cli-windows-386.exe'
          direct_asset_path: '/bin/release-cli-windows-386.exe'
        - name: 'windows/amd64'
          url: "$PACKAGE_REGISTRY_URL/$CI_COMMIT_TAG/release-cli-windows-amd64.exe"
          filepath: '/bin/release-cli-windows-amd64.exe'
          direct_asset_path: '/bin/release-cli-windows-amd64.exe'
+5 −5
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ OPTIONS:
   --tag-name value           The tag the release will be created from [$CI_COMMIT_TAG]
   --tag-message value        Message to use if creating a new annotated tag
   --ref value                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 [$CI_COMMIT_SHA]
   --assets-link value        JSON string representation of an asset link (or an array of asset links); (e.g. --assets-link='{"name": "Asset1", "url":"https://example.com/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"}]')
   --assets-link value        JSON string representation of an asset link (or an array of asset links); (e.g. --assets-link='{"name": "Asset1", "url":"https://example.com/some/location/1", "link_type": "other", "direct_asset_path": "xzy" } or --assets-link='[{"name": "Asset1", "url":"https://example.com/some/location/1"}, {"name": "Asset2", "url":"https://example.com/some/location/2"}]')
   --milestone value          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
   --released-at value        The date when the release will be/was ready; defaults to the current time; expected in ISO 8601 format (2019-03-15T08:00:00Z)
   --help, -h                 Show help (default: false)
@@ -239,7 +239,7 @@ release-branch:
    - >
      release-cli create --name release-branch-$CI_JOB_ID --description release-branch-$CI_COMMIT_REF_NAME-$CI_JOB_ID
      --tag-name job-$CI_JOB_ID --ref $CI_COMMIT_SHA
      --assets-link '{"name":"Asset1","url":"https://<domain>/some/location/1","link_type":"other","filepath":"xzy"}'
      --assets-link '{"name":"Asset1","url":"https://<domain>/some/location/1","link_type":"other","direct_asset_path":"xzy"}'
      --assets-link '{"name":"Asset2","url":"https://<domain>/some/location/2"}'
      --milestone "v1.0.0" --milestone "v1.0.0-rc"
      --released-at "2020-06-30T07:00:00Z"
@@ -264,7 +264,7 @@ You can pass the value for `--assets-link` multiple times to generate multiple l
```plaintext
release-cli create --name release-branch-$CI_JOB_ID --description release-branch-$CI_COMMIT_REF_NAME-$CI_JOB_ID
      --tag-name job-$CI_JOB_ID --ref $CI_COMMIT_SHA
      --assets-link '{"name":"Asset1","url":"https://<domain>/some/location/1","link_type":"other","filepath":"xzy"}'
      --assets-link '{"name":"Asset1","url":"https://<domain>/some/location/1","link_type":"other","direct_asset_path":"xzy"}'
      --assets-link '{"name":"Asset2","url":"https://<domain>/some/location/2"}'
      --milestone "v1.0.0" --milestone "v1.0.0-rc"
      --released-at "2020-06-30T07:00:00Z"
@@ -278,12 +278,12 @@ $ release-cli create \
    --name "Release $CI_COMMIT_TAG" \
    --description "Notes: $EXTRA_DESCRIPTION" \
    --tag-name $CI_COMMIT_TAG --ref $CI_COMMIT_SHA \
    --assets-link '{"name":"Asset1","url":"https://<domain>/some/location/1","link_type":"other","filepath":"xzy"}' \
    --assets-link '{"name":"Asset1","url":"https://<domain>/some/location/1","link_type":"other","direct_asset_path":"xzy"}' \
    --assets-link '{"name":"Asset2","url":"https://<domain>/some/location/2"}' --milestone "m1" --milestone "m2" --released-at "2020-08-20T6:42:00Z"

time="2020-08-20T06:48:58Z" level=info msg="Creating Release..." cli=release-cli command=create name="Release v1.9.0-rc" project-id=18239424 ref=56a2713ede44cb567cc26778ae15f11f01a789d5 server-url="https://gitlab.com" tag-name=v1.9.0-rc version="0.3.0~beta.52.g33bbb8d"

time="2020-08-20T06:48:58Z" level=fatal msg="failed to create release: API Error Response status_code: 400 message: Validation failed: Links url is blocked: URI is invalid, Links filepath is invalid" cli=release-cli version="0.3.0~beta.52.g33bbb8d"
time="2020-08-20T06:48:58Z" level=fatal msg="failed to create release: API Error Response status_code: 400 message: Validation failed: Links url is blocked: URI is invalid, Links direct_asset_path is invalid" cli=release-cli version="0.3.0~beta.52.g33bbb8d"
```

## Examples
+5 −5
Original line number Diff line number Diff line
@@ -58,20 +58,20 @@ func TestApp(t *testing.T) {
		"success_with_assets_link_json": {
			res: testdata.ResponseCreateReleaseSuccess,
			args: []string{"create", "--name", "release name", "--description", "release description", "--tag-name", "v1.1.0",
				"--assets-link", `{"name":"Asset1","url":"https://<domain>/some/location/1","link_type":"other","filepath":"xzy1"}`},
				"--assets-link", `{"name":"Asset1","url":"https://<domain>/some/location/1","link_type":"other","direct_asset_path":"xzy1"}`},
			wantLogEntries: []string{"Creating Release...", "release created successfully!"},
		},
		"success_with_array_of_assets_link_json": {
			res: testdata.ResponseCreateReleaseSuccess,
			args: []string{"create", "--name", "release name", "--description", "release description", "--tag-name", "v1.1.0",
				"--assets-link", `[{"name":"Asset1","url":"https://<domain>/some/location/1","link_type":"other","filepath":"xzy1"}, {"name":"Asset2","url":"https://<domain>/some/location/2","link_type":"other","filepath":"xzy2"}]`},
				"--assets-link", `[{"name":"Asset1","url":"https://<domain>/some/location/1","link_type":"other","direct_asset_path":"xzy1"}, {"name":"Asset2","url":"https://<domain>/some/location/2","link_type":"other","direct_asset_path":"xzy2"}]`},
			wantLogEntries: []string{"Creating Release...", "release created successfully!"},
		},
		"success_with_one_asset_and_array_of_assets_link_json": {
			res: testdata.ResponseCreateReleaseSuccess,
			args: []string{"create", "--name", "release name", "--description", "release description", "--tag-name", "v1.1.0",
				"--assets-link", `[{"name":"Asset1","url":"https://<domain>/some/location/1","link_type":"other","filepath":"xzy1"}, {"name":"Asset2","url":"https://<domain>/some/location/2","link_type":"other","filepath":"xzy2"}]`,
				"--assets-link", `{"name":"Asset3","url":"https://<domain>/some/location/3","link_type":"other","filepath":"xzy3"}`},
				"--assets-link", `[{"name":"Asset1","url":"https://<domain>/some/location/1","link_type":"other","direct_asset_path":"xzy1"}, {"name":"Asset2","url":"https://<domain>/some/location/2","link_type":"other","direct_asset_path":"xzy2"}]`,
				"--assets-link", `{"name":"Asset3","url":"https://<domain>/some/location/3","link_type":"other","direct_asset_path":"xzy3"}`},
			wantLogEntries: []string{"Creating Release...", "release created successfully!"},
		},
		"failed_with_assets_not_json": {
@@ -84,7 +84,7 @@ func TestApp(t *testing.T) {
		"failed_with_one_good_asset_and_one_asset_not_json": {
			res: testdata.ResponseCreateReleaseSuccess,
			args: []string{"create", "--name", "release name", "--description", "release description", "--tag-name", "v1.1.0",
				"--assets-link", `{"name":"Asset1","url":"https://<domain>/some/location/1","link_type":"other","filepath":"xzy1"}`,
				"--assets-link", `{"name":"Asset1","url":"https://<domain>/some/location/1","link_type":"other","direct_asset_path":"xzy1"}`,
				"--assets-link", "not_json"},
			wantErrStr:     "new CreateReleaseRequest: failed to parse assets: 1 error occurred:\n\t* invalid delimiter for asset: \"not_json\"\n\n",
			wantLogEntries: []string{"Creating Release..."},
+4 −4
Original line number Diff line number Diff line
@@ -69,13 +69,13 @@ func TestCreateAssets(t *testing.T) {
	}{
		{
			name:      "success_with_assets_link_json",
			extraArgs: []string{"--assets-link", `{"name":"Asset1","url":"https://<domain>/some/location/1","link_type":"other","filepath":"xzy1"}`},
			extraArgs: []string{"--assets-link", `{"name":"Asset1","url":"https://<domain>/some/location/1","link_type":"other","direct_asset_path":"xzy1"}`},
		},
		{
			name: "success_with_multiple_assets_link_json",
			extraArgs: []string{"--assets-link", `{"name":"Asset1","url":"https://<domain>/some/location/1","link_type":"other","filepath":"xzy1"}`,
				"--assets-link", `{"name":"Asset2","url":"https://<domain>/some/location/2","link_type":"other","filepath":"xzy2"}`,
				"--assets-link", `{"name":"Asset3","url":"https://<domain>/some/location/3","link_type":"other","filepath":"xzy3"}`},
			extraArgs: []string{"--assets-link", `{"name":"Asset1","url":"https://<domain>/some/location/1","link_type":"other","direct_asset_path":"xzy1"}`,
				"--assets-link", `{"name":"Asset2","url":"https://<domain>/some/location/2","link_type":"other","direct_asset_path":"xzy2"}`,
				"--assets-link", `{"name":"Asset3","url":"https://<domain>/some/location/3","link_type":"other","direct_asset_path":"xzy3"}`},
		},
		{
			name:           "failed_with_invalid_assets_link_json",
+1 −1
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ func refFlag(hidden bool) *cli.StringFlag {
func assetsLinkFlag(hidden bool) *cli.StringSliceFlag {
	return &cli.StringSliceFlag{
		Name:     AssetsLink,
		Usage:    `JSON string representation of an asset link; (e.g. --assets-link='{"name": "Asset1", "url":"https://<domain>/some/location/1", "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"}]'`,
		Usage:    `JSON string representation of an asset link; (e.g. --assets-link='{"name": "Asset1", "url":"https://<domain>/some/location/1", "type": "other", "direct_asset_path": "xzy" }' or --assets-link='[{"name": "Asset1", "url":"https://example.com/some/location/1"}, {"name": "Asset2", "url":"https://example.com/some/location/2"}]'. The filepath field is deprecated and aliased to the direct_asset_path field. If both are set the direct_asset_path takes precedence.`,
		Required: false,
		Hidden:   hidden,
	}
Loading