You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

516 lines
14 KiB

10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
Add Attachment API (#3478) * Add Attachment API * repos/:owner/:repo/releases (add attachments) * repos/:owner/:repo/releases/:id (add attachments) * repos/:owner/:repo/releases/:id/attachments * repos/:owner/:repo/releases/:id/attachments/:attachment_id Signed-off-by: Jonas Franz <info@jonasfranz.de> * Add unit tests for new attachment functions Fix comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * fix lint * Update vendor.json Signed-off-by: Jonas Franz <info@jonasfranz.software> * remove version of sdk Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests Add missing license header Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add CreateReleaseAttachment Add EditReleaseAttachment Add DeleteReleaseAttachment Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add filename query parameter for choosing another name for an attachment Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix order of imports Signed-off-by: Jonas Franz <info@jonasfranz.software> * Restricting updatable attachment columns Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update go-sdk Replace Attachments with Assets Signed-off-by: Jonas Franz <info@jonasfranz.de> * Update go-sdk Signed-off-by: Jonas Franz <info@jonasfranz.de> * Updating go-sdk and regenerating swagger Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing file of go-sdk Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change origin of code.gitea.io/sdk to code.gitea.io/sdk Update code.gitea.io/sdk Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update swagger Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update updateAttachment
6 years ago
Add Attachment API (#3478) * Add Attachment API * repos/:owner/:repo/releases (add attachments) * repos/:owner/:repo/releases/:id (add attachments) * repos/:owner/:repo/releases/:id/attachments * repos/:owner/:repo/releases/:id/attachments/:attachment_id Signed-off-by: Jonas Franz <info@jonasfranz.de> * Add unit tests for new attachment functions Fix comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * fix lint * Update vendor.json Signed-off-by: Jonas Franz <info@jonasfranz.software> * remove version of sdk Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests Add missing license header Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add CreateReleaseAttachment Add EditReleaseAttachment Add DeleteReleaseAttachment Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add filename query parameter for choosing another name for an attachment Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix order of imports Signed-off-by: Jonas Franz <info@jonasfranz.software> * Restricting updatable attachment columns Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update go-sdk Replace Attachments with Assets Signed-off-by: Jonas Franz <info@jonasfranz.de> * Update go-sdk Signed-off-by: Jonas Franz <info@jonasfranz.de> * Updating go-sdk and regenerating swagger Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing file of go-sdk Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change origin of code.gitea.io/sdk to code.gitea.io/sdk Update code.gitea.io/sdk Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update swagger Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update updateAttachment
6 years ago
Add Attachment API (#3478) * Add Attachment API * repos/:owner/:repo/releases (add attachments) * repos/:owner/:repo/releases/:id (add attachments) * repos/:owner/:repo/releases/:id/attachments * repos/:owner/:repo/releases/:id/attachments/:attachment_id Signed-off-by: Jonas Franz <info@jonasfranz.de> * Add unit tests for new attachment functions Fix comments Signed-off-by: Jonas Franz <info@jonasfranz.software> * fix lint * Update vendor.json Signed-off-by: Jonas Franz <info@jonasfranz.software> * remove version of sdk Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix unit tests Add missing license header Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add CreateReleaseAttachment Add EditReleaseAttachment Add DeleteReleaseAttachment Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add filename query parameter for choosing another name for an attachment Signed-off-by: Jonas Franz <info@jonasfranz.software> * Fix order of imports Signed-off-by: Jonas Franz <info@jonasfranz.software> * Restricting updatable attachment columns Signed-off-by: Jonas Franz <info@jonasfranz.software> * gofmt Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update go-sdk Replace Attachments with Assets Signed-off-by: Jonas Franz <info@jonasfranz.de> * Update go-sdk Signed-off-by: Jonas Franz <info@jonasfranz.de> * Updating go-sdk and regenerating swagger Signed-off-by: Jonas Franz <info@jonasfranz.software> * Add missing file of go-sdk Signed-off-by: Jonas Franz <info@jonasfranz.software> * Change origin of code.gitea.io/sdk to code.gitea.io/sdk Update code.gitea.io/sdk Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update swagger Signed-off-by: Jonas Franz <info@jonasfranz.software> * Update updateAttachment
6 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
10 years ago
9 years ago
10 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "fmt"
  7. "sort"
  8. "strings"
  9. "code.gitea.io/git"
  10. "code.gitea.io/gitea/modules/log"
  11. "code.gitea.io/gitea/modules/process"
  12. "code.gitea.io/gitea/modules/setting"
  13. "code.gitea.io/gitea/modules/util"
  14. api "code.gitea.io/sdk/gitea"
  15. "github.com/go-xorm/builder"
  16. )
  17. // Release represents a release of repository.
  18. type Release struct {
  19. ID int64 `xorm:"pk autoincr"`
  20. RepoID int64 `xorm:"INDEX UNIQUE(n)"`
  21. Repo *Repository `xorm:"-"`
  22. PublisherID int64 `xorm:"INDEX"`
  23. Publisher *User `xorm:"-"`
  24. TagName string `xorm:"INDEX UNIQUE(n)"`
  25. LowerTagName string
  26. Target string
  27. Title string
  28. Sha1 string `xorm:"VARCHAR(40)"`
  29. NumCommits int64
  30. NumCommitsBehind int64 `xorm:"-"`
  31. Note string `xorm:"TEXT"`
  32. IsDraft bool `xorm:"NOT NULL DEFAULT false"`
  33. IsPrerelease bool `xorm:"NOT NULL DEFAULT false"`
  34. IsTag bool `xorm:"NOT NULL DEFAULT false"`
  35. Attachments []*Attachment `xorm:"-"`
  36. CreatedUnix util.TimeStamp `xorm:"INDEX"`
  37. }
  38. func (r *Release) loadAttributes(e Engine) error {
  39. var err error
  40. if r.Repo == nil {
  41. r.Repo, err = GetRepositoryByID(r.RepoID)
  42. if err != nil {
  43. return err
  44. }
  45. }
  46. if r.Publisher == nil {
  47. r.Publisher, err = GetUserByID(r.PublisherID)
  48. if err != nil {
  49. return err
  50. }
  51. }
  52. return GetReleaseAttachments(r)
  53. }
  54. // LoadAttributes load repo and publisher attributes for a release
  55. func (r *Release) LoadAttributes() error {
  56. return r.loadAttributes(x)
  57. }
  58. // APIURL the api url for a release. release must have attributes loaded
  59. func (r *Release) APIURL() string {
  60. return fmt.Sprintf("%sapi/v1/%s/releases/%d",
  61. setting.AppURL, r.Repo.FullName(), r.ID)
  62. }
  63. // ZipURL the zip url for a release. release must have attributes loaded
  64. func (r *Release) ZipURL() string {
  65. return fmt.Sprintf("%s/archive/%s.zip", r.Repo.HTMLURL(), r.TagName)
  66. }
  67. // TarURL the tar.gz url for a release. release must have attributes loaded
  68. func (r *Release) TarURL() string {
  69. return fmt.Sprintf("%s/archive/%s.tar.gz", r.Repo.HTMLURL(), r.TagName)
  70. }
  71. // APIFormat convert a Release to api.Release
  72. func (r *Release) APIFormat() *api.Release {
  73. assets := make([]*api.Attachment, 0)
  74. for _, att := range r.Attachments {
  75. assets = append(assets, att.APIFormat())
  76. }
  77. return &api.Release{
  78. ID: r.ID,
  79. TagName: r.TagName,
  80. Target: r.Target,
  81. Title: r.Title,
  82. Note: r.Note,
  83. URL: r.APIURL(),
  84. TarURL: r.TarURL(),
  85. ZipURL: r.ZipURL(),
  86. IsDraft: r.IsDraft,
  87. IsPrerelease: r.IsPrerelease,
  88. CreatedAt: r.CreatedUnix.AsTime(),
  89. PublishedAt: r.CreatedUnix.AsTime(),
  90. Publisher: r.Publisher.APIFormat(),
  91. Attachments: assets,
  92. }
  93. }
  94. // IsReleaseExist returns true if release with given tag name already exists.
  95. func IsReleaseExist(repoID int64, tagName string) (bool, error) {
  96. if len(tagName) == 0 {
  97. return false, nil
  98. }
  99. return x.Get(&Release{RepoID: repoID, LowerTagName: strings.ToLower(tagName)})
  100. }
  101. func createTag(gitRepo *git.Repository, rel *Release) error {
  102. // Only actual create when publish.
  103. if !rel.IsDraft {
  104. if !gitRepo.IsTagExist(rel.TagName) {
  105. commit, err := gitRepo.GetCommit(rel.Target)
  106. if err != nil {
  107. return fmt.Errorf("GetCommit: %v", err)
  108. }
  109. // Trim '--' prefix to prevent command line argument vulnerability.
  110. rel.TagName = strings.TrimPrefix(rel.TagName, "--")
  111. if err = gitRepo.CreateTag(rel.TagName, commit.ID.String()); err != nil {
  112. if strings.Contains(err.Error(), "is not a valid tag name") {
  113. return ErrInvalidTagName{rel.TagName}
  114. }
  115. return err
  116. }
  117. rel.LowerTagName = strings.ToLower(rel.TagName)
  118. }
  119. commit, err := gitRepo.GetTagCommit(rel.TagName)
  120. if err != nil {
  121. return fmt.Errorf("GetTagCommit: %v", err)
  122. }
  123. rel.Sha1 = commit.ID.String()
  124. rel.CreatedUnix = util.TimeStamp(commit.Author.When.Unix())
  125. rel.NumCommits, err = commit.CommitsCount()
  126. if err != nil {
  127. return fmt.Errorf("CommitsCount: %v", err)
  128. }
  129. } else {
  130. rel.CreatedUnix = util.TimeStampNow()
  131. }
  132. return nil
  133. }
  134. func addReleaseAttachments(releaseID int64, attachmentUUIDs []string) (err error) {
  135. // Check attachments
  136. var attachments = make([]*Attachment, 0)
  137. for _, uuid := range attachmentUUIDs {
  138. attach, err := getAttachmentByUUID(x, uuid)
  139. if err != nil {
  140. if IsErrAttachmentNotExist(err) {
  141. continue
  142. }
  143. return fmt.Errorf("getAttachmentByUUID [%s]: %v", uuid, err)
  144. }
  145. attachments = append(attachments, attach)
  146. }
  147. for i := range attachments {
  148. attachments[i].ReleaseID = releaseID
  149. // No assign value could be 0, so ignore AllCols().
  150. if _, err = x.ID(attachments[i].ID).Update(attachments[i]); err != nil {
  151. return fmt.Errorf("update attachment [%d]: %v", attachments[i].ID, err)
  152. }
  153. }
  154. return
  155. }
  156. // CreateRelease creates a new release of repository.
  157. func CreateRelease(gitRepo *git.Repository, rel *Release, attachmentUUIDs []string) error {
  158. isExist, err := IsReleaseExist(rel.RepoID, rel.TagName)
  159. if err != nil {
  160. return err
  161. } else if isExist {
  162. return ErrReleaseAlreadyExist{rel.TagName}
  163. }
  164. if err = createTag(gitRepo, rel); err != nil {
  165. return err
  166. }
  167. rel.LowerTagName = strings.ToLower(rel.TagName)
  168. _, err = x.InsertOne(rel)
  169. if err != nil {
  170. return err
  171. }
  172. err = addReleaseAttachments(rel.ID, attachmentUUIDs)
  173. if err != nil {
  174. return err
  175. }
  176. if !rel.IsDraft {
  177. if err := rel.LoadAttributes(); err != nil {
  178. log.Error(2, "LoadAttributes: %v", err)
  179. } else {
  180. mode, _ := AccessLevel(rel.Publisher, rel.Repo)
  181. if err := PrepareWebhooks(rel.Repo, HookEventRelease, &api.ReleasePayload{
  182. Action: api.HookReleasePublished,
  183. Release: rel.APIFormat(),
  184. Repository: rel.Repo.APIFormat(mode),
  185. Sender: rel.Publisher.APIFormat(),
  186. }); err != nil {
  187. log.Error(2, "PrepareWebhooks: %v", err)
  188. } else {
  189. go HookQueue.Add(rel.Repo.ID)
  190. }
  191. }
  192. }
  193. return nil
  194. }
  195. // GetRelease returns release by given ID.
  196. func GetRelease(repoID int64, tagName string) (*Release, error) {
  197. isExist, err := IsReleaseExist(repoID, tagName)
  198. if err != nil {
  199. return nil, err
  200. } else if !isExist {
  201. return nil, ErrReleaseNotExist{0, tagName}
  202. }
  203. rel := &Release{RepoID: repoID, LowerTagName: strings.ToLower(tagName)}
  204. _, err = x.Get(rel)
  205. return rel, err
  206. }
  207. // GetReleaseByID returns release with given ID.
  208. func GetReleaseByID(id int64) (*Release, error) {
  209. rel := new(Release)
  210. has, err := x.
  211. ID(id).
  212. Get(rel)
  213. if err != nil {
  214. return nil, err
  215. } else if !has {
  216. return nil, ErrReleaseNotExist{id, ""}
  217. }
  218. return rel, nil
  219. }
  220. // FindReleasesOptions describes the conditions to Find releases
  221. type FindReleasesOptions struct {
  222. IncludeDrafts bool
  223. IncludeTags bool
  224. TagNames []string
  225. }
  226. func (opts *FindReleasesOptions) toConds(repoID int64) builder.Cond {
  227. var cond = builder.NewCond()
  228. cond = cond.And(builder.Eq{"repo_id": repoID})
  229. if !opts.IncludeDrafts {
  230. cond = cond.And(builder.Eq{"is_draft": false})
  231. }
  232. if !opts.IncludeTags {
  233. cond = cond.And(builder.Eq{"is_tag": false})
  234. }
  235. if len(opts.TagNames) > 0 {
  236. cond = cond.And(builder.In("tag_name", opts.TagNames))
  237. }
  238. return cond
  239. }
  240. // GetReleasesByRepoID returns a list of releases of repository.
  241. func GetReleasesByRepoID(repoID int64, opts FindReleasesOptions, page, pageSize int) (rels []*Release, err error) {
  242. if page <= 0 {
  243. page = 1
  244. }
  245. err = x.
  246. Desc("created_unix", "id").
  247. Limit(pageSize, (page-1)*pageSize).
  248. Where(opts.toConds(repoID)).
  249. Find(&rels)
  250. return rels, err
  251. }
  252. // GetReleasesByRepoIDAndNames returns a list of releases of repository according repoID and tagNames.
  253. func GetReleasesByRepoIDAndNames(repoID int64, tagNames []string) (rels []*Release, err error) {
  254. err = x.
  255. Desc("created_unix").
  256. In("tag_name", tagNames).
  257. Find(&rels, Release{RepoID: repoID})
  258. return rels, err
  259. }
  260. // GetReleaseCountByRepoID returns the count of releases of repository
  261. func GetReleaseCountByRepoID(repoID int64, opts FindReleasesOptions) (int64, error) {
  262. return x.Where(opts.toConds(repoID)).Count(&Release{})
  263. }
  264. type releaseMetaSearch struct {
  265. ID []int64
  266. Rel []*Release
  267. }
  268. func (s releaseMetaSearch) Len() int {
  269. return len(s.ID)
  270. }
  271. func (s releaseMetaSearch) Swap(i, j int) {
  272. s.ID[i], s.ID[j] = s.ID[j], s.ID[i]
  273. s.Rel[i], s.Rel[j] = s.Rel[j], s.Rel[i]
  274. }
  275. func (s releaseMetaSearch) Less(i, j int) bool {
  276. return s.ID[i] < s.ID[j]
  277. }
  278. // GetReleaseAttachments retrieves the attachments for releases
  279. func GetReleaseAttachments(rels ...*Release) (err error) {
  280. if len(rels) == 0 {
  281. return
  282. }
  283. // To keep this efficient as possible sort all releases by id,
  284. // select attachments by release id,
  285. // then merge join them
  286. // Sort
  287. var sortedRels = releaseMetaSearch{ID: make([]int64, len(rels)), Rel: make([]*Release, len(rels))}
  288. var attachments []*Attachment
  289. for index, element := range rels {
  290. element.Attachments = []*Attachment{}
  291. sortedRels.ID[index] = element.ID
  292. sortedRels.Rel[index] = element
  293. }
  294. sort.Sort(sortedRels)
  295. // Select attachments
  296. err = x.
  297. Asc("release_id").
  298. In("release_id", sortedRels.ID).
  299. Find(&attachments, Attachment{})
  300. if err != nil {
  301. return err
  302. }
  303. // merge join
  304. var currentIndex = 0
  305. for _, attachment := range attachments {
  306. for sortedRels.ID[currentIndex] < attachment.ReleaseID {
  307. currentIndex++
  308. }
  309. sortedRels.Rel[currentIndex].Attachments = append(sortedRels.Rel[currentIndex].Attachments, attachment)
  310. }
  311. return
  312. }
  313. type releaseSorter struct {
  314. rels []*Release
  315. }
  316. func (rs *releaseSorter) Len() int {
  317. return len(rs.rels)
  318. }
  319. func (rs *releaseSorter) Less(i, j int) bool {
  320. diffNum := rs.rels[i].NumCommits - rs.rels[j].NumCommits
  321. if diffNum != 0 {
  322. return diffNum > 0
  323. }
  324. return rs.rels[i].CreatedUnix > rs.rels[j].CreatedUnix
  325. }
  326. func (rs *releaseSorter) Swap(i, j int) {
  327. rs.rels[i], rs.rels[j] = rs.rels[j], rs.rels[i]
  328. }
  329. // SortReleases sorts releases by number of commits and created time.
  330. func SortReleases(rels []*Release) {
  331. sorter := &releaseSorter{rels: rels}
  332. sort.Sort(sorter)
  333. }
  334. // UpdateRelease updates information of a release.
  335. func UpdateRelease(doer *User, gitRepo *git.Repository, rel *Release, attachmentUUIDs []string) (err error) {
  336. if err = createTag(gitRepo, rel); err != nil {
  337. return err
  338. }
  339. rel.LowerTagName = strings.ToLower(rel.TagName)
  340. _, err = x.ID(rel.ID).AllCols().Update(rel)
  341. if err != nil {
  342. return err
  343. }
  344. err = rel.loadAttributes(x)
  345. if err != nil {
  346. return err
  347. }
  348. err = addReleaseAttachments(rel.ID, attachmentUUIDs)
  349. mode, _ := AccessLevel(doer, rel.Repo)
  350. if err1 := PrepareWebhooks(rel.Repo, HookEventRelease, &api.ReleasePayload{
  351. Action: api.HookReleaseUpdated,
  352. Release: rel.APIFormat(),
  353. Repository: rel.Repo.APIFormat(mode),
  354. Sender: rel.Publisher.APIFormat(),
  355. }); err1 != nil {
  356. log.Error(2, "PrepareWebhooks: %v", err)
  357. } else {
  358. go HookQueue.Add(rel.Repo.ID)
  359. }
  360. return err
  361. }
  362. // DeleteReleaseByID deletes a release and corresponding Git tag by given ID.
  363. func DeleteReleaseByID(id int64, u *User, delTag bool) error {
  364. rel, err := GetReleaseByID(id)
  365. if err != nil {
  366. return fmt.Errorf("GetReleaseByID: %v", err)
  367. }
  368. repo, err := GetRepositoryByID(rel.RepoID)
  369. if err != nil {
  370. return fmt.Errorf("GetRepositoryByID: %v", err)
  371. }
  372. if delTag {
  373. _, stderr, err := process.GetManager().ExecDir(-1, repo.RepoPath(),
  374. fmt.Sprintf("DeleteReleaseByID (git tag -d): %d", rel.ID),
  375. "git", "tag", "-d", rel.TagName)
  376. if err != nil && !strings.Contains(stderr, "not found") {
  377. return fmt.Errorf("git tag -d: %v - %s", err, stderr)
  378. }
  379. if _, err = x.ID(rel.ID).Delete(new(Release)); err != nil {
  380. return fmt.Errorf("Delete: %v", err)
  381. }
  382. } else {
  383. rel.IsTag = true
  384. rel.IsDraft = false
  385. rel.IsPrerelease = false
  386. rel.Title = ""
  387. rel.Note = ""
  388. if _, err = x.ID(rel.ID).AllCols().Update(rel); err != nil {
  389. return fmt.Errorf("Update: %v", err)
  390. }
  391. }
  392. rel.Repo = repo
  393. if err = rel.LoadAttributes(); err != nil {
  394. return fmt.Errorf("LoadAttributes: %v", err)
  395. }
  396. mode, _ := AccessLevel(u, rel.Repo)
  397. if err := PrepareWebhooks(rel.Repo, HookEventRelease, &api.ReleasePayload{
  398. Action: api.HookReleaseDeleted,
  399. Release: rel.APIFormat(),
  400. Repository: rel.Repo.APIFormat(mode),
  401. Sender: rel.Publisher.APIFormat(),
  402. }); err != nil {
  403. log.Error(2, "PrepareWebhooks: %v", err)
  404. } else {
  405. go HookQueue.Add(rel.Repo.ID)
  406. }
  407. return nil
  408. }
  409. // SyncReleasesWithTags synchronizes release table with repository tags
  410. func SyncReleasesWithTags(repo *Repository, gitRepo *git.Repository) error {
  411. existingRelTags := make(map[string]struct{})
  412. opts := FindReleasesOptions{IncludeDrafts: true, IncludeTags: true}
  413. for page := 1; ; page++ {
  414. rels, err := GetReleasesByRepoID(repo.ID, opts, page, 100)
  415. if err != nil {
  416. return fmt.Errorf("GetReleasesByRepoID: %v", err)
  417. }
  418. if len(rels) == 0 {
  419. break
  420. }
  421. for _, rel := range rels {
  422. if rel.IsDraft {
  423. continue
  424. }
  425. commitID, err := gitRepo.GetTagCommitID(rel.TagName)
  426. if err != nil && !git.IsErrNotExist(err) {
  427. return fmt.Errorf("GetTagCommitID: %v", err)
  428. }
  429. if git.IsErrNotExist(err) || commitID != rel.Sha1 {
  430. if err := pushUpdateDeleteTag(repo, gitRepo, rel.TagName); err != nil {
  431. return fmt.Errorf("pushUpdateDeleteTag: %v", err)
  432. }
  433. } else {
  434. existingRelTags[strings.ToLower(rel.TagName)] = struct{}{}
  435. }
  436. }
  437. }
  438. tags, err := gitRepo.GetTags()
  439. if err != nil {
  440. return fmt.Errorf("GetTags: %v", err)
  441. }
  442. for _, tagName := range tags {
  443. if _, ok := existingRelTags[strings.ToLower(tagName)]; !ok {
  444. if err := pushUpdateAddTag(repo, gitRepo, tagName); err != nil {
  445. return fmt.Errorf("pushUpdateAddTag: %v", err)
  446. }
  447. }
  448. }
  449. return nil
  450. }