Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API] Add repoCreateTag function #14669

Closed
6543 opened this issue Feb 13, 2021 · 4 comments · Fixed by #16165
Closed

[API] Add repoCreateTag function #14669

6543 opened this issue Feb 13, 2021 · 4 comments · Fixed by #16165
Labels
modifies/api This PR adds API routes or modifies them
Milestone

Comments

@6543
Copy link
Member

6543 commented Feb 13, 2021

POST /repos/{owner}/{repo}/tags to create a tag

@6543 6543 added good first issue Likely to be an easy fix modifies/api This PR adds API routes or modifies them labels Feb 13, 2021
@6543 6543 added this to the 1.15.0 milestone Feb 13, 2021
@radiohertz
Copy link

Hey @6543, I'd like to look into this. As a newcomer few pointers would be helpful. :)

@6543
Copy link
Member Author

6543 commented Mar 21, 2021

first start is to read the CONTRIBUTING.md especially the API v1 section

for this issue you can have a look how CreateRelease works

func CreateRelease(ctx *context.APIContext) {
// swagger:operation POST /repos/{owner}/{repo}/releases repository repoCreateRelease
// ---
// summary: Create a release
// consumes:
// - application/json
// produces:
// - application/json
// parameters:
// - name: owner
// in: path
// description: owner of the repo
// type: string
// required: true
// - name: repo
// in: path
// description: name of the repo
// type: string
// required: true
// - name: body
// in: body
// schema:
// "$ref": "#/definitions/CreateReleaseOption"
// responses:
// "201":
// "$ref": "#/responses/Release"
// "404":
// "$ref": "#/responses/notFound"
// "409":
// "$ref": "#/responses/error"
form := web.GetForm(ctx).(*api.CreateReleaseOption)
rel, err := models.GetRelease(ctx.Repo.Repository.ID, form.TagName)
if err != nil {
if !models.IsErrReleaseNotExist(err) {
ctx.Error(http.StatusInternalServerError, "GetRelease", err)
return
}
// If target is not provided use default branch
if len(form.Target) == 0 {
form.Target = ctx.Repo.Repository.DefaultBranch
}
rel = &models.Release{
RepoID: ctx.Repo.Repository.ID,
PublisherID: ctx.User.ID,
Publisher: ctx.User,
TagName: form.TagName,
Target: form.Target,
Title: form.Title,
Note: form.Note,
IsDraft: form.IsDraft,
IsPrerelease: form.IsPrerelease,
IsTag: false,
Repo: ctx.Repo.Repository,
}
if err := releaseservice.CreateRelease(ctx.Repo.GitRepo, rel, nil, ""); err != nil {
if models.IsErrReleaseAlreadyExist(err) {
ctx.Error(http.StatusConflict, "ReleaseAlreadyExist", err)
} else {
ctx.Error(http.StatusInternalServerError, "CreateRelease", err)
}
return
}
} else {
if !rel.IsTag {
ctx.Error(http.StatusConflict, "GetRelease", "Release is has no Tag")
return
}
rel.Title = form.Title
rel.Note = form.Note
rel.IsDraft = form.IsDraft
rel.IsPrerelease = form.IsPrerelease
rel.PublisherID = ctx.User.ID
rel.IsTag = false
rel.Repo = ctx.Repo.Repository
rel.Publisher = ctx.User
if err = releaseservice.UpdateReleaseOrCreatReleaseFromTag(ctx.User, ctx.Repo.GitRepo, rel, nil, true); err != nil {
ctx.Error(http.StatusInternalServerError, "UpdateReleaseOrCreatReleaseFromTag", err)
return
}
}
ctx.JSON(http.StatusCreated, convert.ToRelease(rel))
}

just remove unnecessary options & tell releaseservice.CreateRelease to only create a tag but no release :)

@6543
Copy link
Member Author

6543 commented Mar 21, 2021

@segfult if you have specific questions just PM me via Discord

@radiohertz
Copy link

@segfult if you have specific questions just PM me via Discord

will do, thanks.

@6543 6543 removed the good first issue Likely to be an easy fix label Jun 15, 2021
@go-gitea go-gitea locked and limited conversation to collaborators Oct 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
modifies/api This PR adds API routes or modifies them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants