From 825efa2605421a54ad1c5960de9e121a34d68d1a Mon Sep 17 00:00:00 2001
From: zeripath <art27@cantab.net>
Date: Sun, 13 Dec 2020 11:34:11 +0000
Subject: [PATCH] [API] Add Ref to Issue (#13946)

* Add Ref to api.Issue

This PR adds Ref to api.Issue and adds the backend parts to the migrator.

Fix #13918

Signed-off-by: Andrew Thornton <art27@cantab.net>
---
 modules/convert/issue.go             | 1 +
 modules/migrations/base/issue.go     | 1 +
 modules/migrations/gitea_uploader.go | 1 +
 modules/structs/issue.go             | 1 +
 templates/swagger/v1_json.tmpl       | 4 ++++
 5 files changed, 8 insertions(+)

diff --git a/modules/convert/issue.go b/modules/convert/issue.go
index f34656b47c..36446da2d1 100644
--- a/modules/convert/issue.go
+++ b/modules/convert/issue.go
@@ -34,6 +34,7 @@ func ToAPIIssue(issue *models.Issue) *api.Issue {
 		Poster:   ToUser(issue.Poster, false, false),
 		Title:    issue.Title,
 		Body:     issue.Content,
+		Ref:      issue.Ref,
 		Labels:   ToLabelList(issue.Labels),
 		State:    issue.State(),
 		IsLocked: issue.IsLocked,
diff --git a/modules/migrations/base/issue.go b/modules/migrations/base/issue.go
index b9625a23f6..f9dc8b93fe 100644
--- a/modules/migrations/base/issue.go
+++ b/modules/migrations/base/issue.go
@@ -15,6 +15,7 @@ type Issue struct {
 	PosterEmail string
 	Title       string
 	Content     string
+	Ref         string
 	Milestone   string
 	State       string // closed, open
 	IsLocked    bool
diff --git a/modules/migrations/gitea_uploader.go b/modules/migrations/gitea_uploader.go
index 2cb19685fc..20d7d81ae1 100644
--- a/modules/migrations/gitea_uploader.go
+++ b/modules/migrations/gitea_uploader.go
@@ -333,6 +333,7 @@ func (g *GiteaLocalUploader) CreateIssues(issues ...*base.Issue) error {
 			Index:       issue.Number,
 			Title:       issue.Title,
 			Content:     issue.Content,
+			Ref:         issue.Ref,
 			IsClosed:    issue.State == "closed",
 			IsLocked:    issue.IsLocked,
 			MilestoneID: milestoneID,
diff --git a/modules/structs/issue.go b/modules/structs/issue.go
index 54b0f31d8a..06ad2de322 100644
--- a/modules/structs/issue.go
+++ b/modules/structs/issue.go
@@ -47,6 +47,7 @@ type Issue struct {
 	OriginalAuthorID int64      `json:"original_author_id"`
 	Title            string     `json:"title"`
 	Body             string     `json:"body"`
+	Ref              string     `json:"ref"`
 	Labels           []*Label   `json:"labels"`
 	Milestone        *Milestone `json:"milestone"`
 	Assignee         *User      `json:"assignee"`
diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl
index bf8467ff27..e77651b15e 100644
--- a/templates/swagger/v1_json.tmpl
+++ b/templates/swagger/v1_json.tmpl
@@ -13831,6 +13831,10 @@
         "pull_request": {
           "$ref": "#/definitions/PullRequestMeta"
         },
+        "ref": {
+          "type": "string",
+          "x-go-name": "Ref"
+        },
         "repository": {
           "$ref": "#/definitions/RepositoryMeta"
         },