(gitRepo *git.Repository, r *Release)
| 113 | } |
| 114 | |
| 115 | func createTag(gitRepo *git.Repository, r *Release) error { |
| 116 | // Only actual create when publish. |
| 117 | if !r.IsDraft { |
| 118 | if !gitRepo.HasTag(r.TagName) { |
| 119 | commit, err := gitRepo.BranchCommit(r.Target) |
| 120 | if err != nil { |
| 121 | return errors.Newf("get branch commit: %v", err) |
| 122 | } |
| 123 | |
| 124 | // 🚨 SECURITY: Trim any leading '-' to prevent command line argument injection. |
| 125 | r.TagName = strings.TrimLeft(r.TagName, "-") |
| 126 | if err = gitRepo.CreateTag(r.TagName, commit.ID.String()); err != nil { |
| 127 | if strings.Contains(err.Error(), "is not a valid tag name") { |
| 128 | return ErrInvalidTagName{r.TagName} |
| 129 | } |
| 130 | return err |
| 131 | } |
| 132 | } else { |
| 133 | commit, err := gitRepo.TagCommit(r.TagName) |
| 134 | if err != nil { |
| 135 | return errors.Newf("get tag commit: %v", err) |
| 136 | } |
| 137 | |
| 138 | r.Sha1 = commit.ID.String() |
| 139 | r.NumCommits, err = commit.CommitsCount() |
| 140 | if err != nil { |
| 141 | return errors.Newf("count commits: %v", err) |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | return nil |
| 146 | } |
| 147 | |
| 148 | func (r *Release) preparePublishWebhooks() { |
| 149 | if err := PrepareWebhooks(r.Repo, HookEventTypeRelease, &api.ReleasePayload{ |
no test coverage detected