You've already forked goreleaser
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:
@@ -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(
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user