1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-09-16 09:26:52 +02:00

feat(gitlab): use project id (#2297)

* feat: use project id

* fix: missing slash.

* Added comment.

* Added a comment

Signed-off-by: Jesse Quinn <jesse.quinn@zpesystems.com>

* Added a comment

Signed-off-by: Jesse Quinn <me@jessequinn.info>

Co-authored-by: Jesse Quinn <jesse.quinn@zpesystems.com>
Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
This commit is contained in:
Jesse Quinn
2021-06-26 16:44:24 -03:00
committed by GitHub
parent 1883ed4a73
commit 92a4afb169
2 changed files with 51 additions and 12 deletions

View File

@@ -191,11 +191,18 @@ func (c *gitlabClient) CreateRelease(ctx *context.Context, body string) (release
if err != nil {
return "", err
}
projectID := ctx.Config.Release.GitLab.Owner + "/" + ctx.Config.Release.GitLab.Name
gitlabName, err := tmpl.New(ctx).Apply(ctx.Config.Release.GitLab.Name)
if err != nil {
return "", err
}
projectID := gitlabName
if ctx.Config.Release.GitLab.Owner != "" {
projectID = ctx.Config.Release.GitLab.Owner + "/" + projectID
}
log.WithFields(log.Fields{
"owner": ctx.Config.Release.GitLab.Owner,
"name": ctx.Config.Release.GitLab.Name,
"owner": ctx.Config.Release.GitLab.Owner,
"name": gitlabName,
"projectID": projectID,
}).Debug("projectID")
name := title
@@ -258,12 +265,26 @@ func (c *gitlabClient) CreateRelease(ctx *context.Context, body string) (release
}
func (c *gitlabClient) ReleaseURLTemplate(ctx *context.Context) (string, error) {
return fmt.Sprintf(
"%s/%s/%s/-/releases/{{ .Tag }}/downloads/{{ .ArtifactName }}",
ctx.Config.GitLabURLs.Download,
ctx.Config.Release.GitLab.Owner,
ctx.Config.Release.GitLab.Name,
), nil
var urlTemplate string
gitlabName, err := tmpl.New(ctx).Apply(ctx.Config.Release.GitLab.Name)
if err != nil {
return "", err
}
if ctx.Config.Release.GitLab.Owner != "" {
urlTemplate = fmt.Sprintf(
"%s/%s/%s/-/releases/{{ .Tag }}/downloads/{{ .ArtifactName }}",
ctx.Config.GitLabURLs.Download,
ctx.Config.Release.GitLab.Owner,
gitlabName,
)
} else {
urlTemplate = fmt.Sprintf(
"%s/%s/-/releases/{{ .Tag }}/downloads/{{ .ArtifactName }}",
ctx.Config.GitLabURLs.Download,
gitlabName,
)
}
return urlTemplate, nil
}
// Upload uploads a file into a release repository.
@@ -273,7 +294,16 @@ func (c *gitlabClient) Upload(
artifact *artifact.Artifact,
file *os.File,
) error {
projectID := ctx.Config.Release.GitLab.Owner + "/" + ctx.Config.Release.GitLab.Name
// create new template and apply name field
gitlabName, err := tmpl.New(ctx).Apply(ctx.Config.Release.GitLab.Name)
if err != nil {
return err
}
projectID := gitlabName
// check if owner is empty
if ctx.Config.Release.GitLab.Owner != "" {
projectID = ctx.Config.Release.GitLab.Owner + "/" + projectID
}
log.WithField("file", file.Name()).Debug("uploading file")
projectFile, _, err := c.client.Projects.UploadFile(
@@ -290,9 +320,15 @@ func (c *gitlabClient) Upload(
"url": projectFile.URL,
}).Debug("uploaded file")
// search for project details based on projectID
projectDetails, _, err := c.client.Projects.GetProject(projectID, nil)
if err != nil {
return err
}
gitlabBaseURL := ctx.Config.GitLabURLs.Download
// projectFile.URL from upload: /uploads/<hash>/filename.txt
linkURL := gitlabBaseURL + "/" + projectID + projectFile.URL
linkURL := gitlabBaseURL + "/" + projectDetails.PathWithNamespace + projectFile.URL
name := artifact.Name
filename := "/" + name
releaseLink, _, err := c.client.ReleaseLinks.CreateReleaseLink(

View File

@@ -14,6 +14,9 @@ release:
# Repo in which the release will be created.
# Default is extracted from the origin remote URL or empty if its private hosted.
# Note: it can only be one: either github, gitlab or gitea
# You can use Gitlab's internal project id by setting it directly or using an environment variable
# owner: ""
# name: "{{.Env.CI_PROJECT_ID}}"
github:
owner: user
name: repo