From 5cf20579d2fd8aaf089276ea92235edf5a50d546 Mon Sep 17 00:00:00 2001 From: avadesian Date: Mon, 11 Oct 2021 15:22:11 +0800 Subject: [PATCH 1/8] add new feature fetch upstream --- options/locale/locale_en-US.ini | 4 ++++ options/locale/locale_zh-CN.ini | 4 ++++ routers/repo/view.go | 35 +++++++++++++++++++++++++++++++++++ templates/repo/home.tmpl | 11 +++++++++++ 4 files changed, 54 insertions(+) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 50e85ba27..5ea80af77 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1241,6 +1241,10 @@ pulls.reject_count_1 = "%d change request" pulls.reject_count_n = "%d change requests" pulls.waiting_count_1 = "%d waiting review" pulls.waiting_count_n = "%d waiting reviews" +pulls.commits_count_1=This branch is %d commit behind the upstream. +pulls.commits_count_n=This branch is %d commit behind the upstream. +pulls.fetch_upstream=Fetch upstream +pulls.upstream_up_to_date=No new commits to fetch pulls.no_merge_desc = This pull request cannot be merged because all repository merge options are disabled. pulls.no_merge_helper = Enable merge options in the repository settings or merge the pull request manually. diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index 89a6282e5..3774668bb 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -1243,6 +1243,10 @@ pulls.reject_count_1=%d 变更请求 pulls.reject_count_n=%d 变更请求 pulls.waiting_count_1=%d 个正在等待审核 pulls.waiting_count_n=%d 个正在等待审核 +pulls.commits_count_1=当前分支落后上游分支 %d 个提交 +pulls.commits_count_n=当前分支落后上游分支 %d 个提交 +pulls.fetch_upstream=拉取上游更新 +pulls.upstream_up_to_date=上游分支没有新的更新 pulls.no_merge_desc=由于未启用合并选项,此合并请求无法被合并。 pulls.no_merge_helper=在项目设置中启用合并选项或者手工合并请求。 diff --git a/routers/repo/view.go b/routers/repo/view.go index 1546f53b7..8c768c9eb 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -790,6 +790,41 @@ func renderCode(ctx *context.Context) { } } + //如果是fork的仓库 + if ctx.Repo.Repository.IsFork { + //获得fetchUpstream对应的分支参数 + /* + // 1. /{:baseOwner}/{:baseRepoName}/compare/{:baseBranch}...{:headBranch} + // 2. /{:baseOwner}/{:baseRepoName}/compare/{:baseBranch}...{:headOwner}:{:headBranch} + // 3. /{:baseOwner}/{:baseRepoName}/compare/{:baseBranch}...{:headOwner}/{:headRepoName}:{:headBranch} + */ + baseGitRepo, err := git.OpenRepository(ctx.Repo.Repository.BaseRepo.RepoPath()) + if err != nil { + log.Error("error open baseRepo:%s",ctx.Repo.Repository.BaseRepo.RepoPath()) + } + defer baseGitRepo.Close() + if _,error:= baseGitRepo.GetBranch(ctx.Repo.BranchName);error==nil{ + //base repo has the same branch, then compare between current repo branch and base repo's branch + compareUrl := ctx.Repo.BranchName + "..." + ctx.Repo.Repository.BaseRepo.OwnerName + "/" + ctx.Repo.Repository.BaseRepo.Name + ":" + ctx.Repo.BranchName + ctx.SetParams("*",compareUrl) + }else{ + //else, compare between current repo branch and base repo's default branch + compareUrl := ctx.Repo.BranchName + "..." + ctx.Repo.Repository.BaseRepo.OwnerName + "/" + ctx.Repo.Repository.BaseRepo.Name + ":" + ctx.Repo.Repository.BaseRepo.DefaultBranch + ctx.SetParams("*",compareUrl) + } + + _, _, headGitRepo, compareInfo, _, _ := ParseCompareInfo(ctx) + defer headGitRepo.Close() + if compareInfo!= nil { + if compareInfo.Commits!=nil { + log.Info("compareInfoCommits数量:%d",compareInfo.Commits.Len()) + ctx.Data["FetchUpstreamCnt"] = compareInfo.Commits.Len() + }else{ + log.Info("compareInfo nothing different") + ctx.Data["FetchUpstreamCnt"] = 0 + } + } + } ctx.Data["Paths"] = paths ctx.Data["TreeLink"] = treeLink ctx.Data["TreeNames"] = treeNames diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index b48efd498..2f123e473 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -119,6 +119,17 @@ + {{if and .Repository.IsFork .PullRequestCtx.Allowed}} + {{if gt .FetchUpstreamCnt 0 }} + + + + {{else}} + + + + {{end}} + {{end}} {{end}} {{else}} From 4d2b7b4642e9e5c8cf25ac498b5cdb9f85261028 Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Tue, 12 Oct 2021 10:30:59 +0800 Subject: [PATCH 2/8] fix issue #427 --- templates/explore/dataset_search.tmpl | 4 ++-- templates/explore/search.tmpl | 4 ++-- templates/repo/datasets/index.tmpl | 4 ++-- templates/repo/issue/search.tmpl | 2 +- templates/user/dashboard/issues.tmpl | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/templates/explore/dataset_search.tmpl b/templates/explore/dataset_search.tmpl index 6c973026a..aad8f5083 100644 --- a/templates/explore/dataset_search.tmpl +++ b/templates/explore/dataset_search.tmpl @@ -1,12 +1,12 @@
-
+
- +
diff --git a/templates/explore/search.tmpl b/templates/explore/search.tmpl index 11e89d50a..4353f7302 100644 --- a/templates/explore/search.tmpl +++ b/templates/explore/search.tmpl @@ -1,11 +1,11 @@
-
+
- +
diff --git a/templates/repo/datasets/index.tmpl b/templates/repo/datasets/index.tmpl index b92d5a1ae..167b1ef44 100755 --- a/templates/repo/datasets/index.tmpl +++ b/templates/repo/datasets/index.tmpl @@ -37,7 +37,7 @@
{{if .Permission.CanWrite $.UnitTypeDatasets}} @@ -66,7 +66,7 @@
{{.i18n.Tr "cancel"}} - +
diff --git a/templates/repo/issue/search.tmpl b/templates/repo/issue/search.tmpl index 632270da8..147f06485 100644 --- a/templates/repo/issue/search.tmpl +++ b/templates/repo/issue/search.tmpl @@ -7,7 +7,7 @@
diff --git a/templates/user/dashboard/issues.tmpl b/templates/user/dashboard/issues.tmpl index ebe552f50..6334ea3dc 100644 --- a/templates/user/dashboard/issues.tmpl +++ b/templates/user/dashboard/issues.tmpl @@ -74,7 +74,7 @@
From f1cd4aa8e46095588ed47bdc2d2ddb0ccd3c0b52 Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 12 Oct 2021 11:11:00 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E5=8E=BB=E6=8E=89=E9=87=8D=E5=A4=8D=E7=9A=84=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=89=80=E6=9C=89=E9=A1=B9=E7=9B=AE=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_business_analysis.go | 10 ---------- routers/repo/user_data_analysis.go | 6 +++++- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index 9da0694a5..a00aef0c8 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -344,13 +344,3 @@ func subMonth(t1, t2 time.Time) (month int) { month = yearInterval*12 + monthInterval return month } - -func QueryAllRepo() []*Repository { - sess := x.NewSession() - defer sess.Close() - sess.Select("*").Table("repository") - repositoryList := make([]*Repository, 0) - sess.Find(&repositoryList) - - return repositoryList -} diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index 13850af7a..2d9c03e1d 100644 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -18,7 +18,11 @@ func TimeingCountData() { yesterday := currentTimeNow.AddDate(0, 0, -1) - repoList := models.QueryAllRepo() + repoList, err := models.GetAllRepositories() + if err != nil { + log.Error("query repo error.") + return + } log.Info("start to query wiki data") for _, repoRecord := range repoList { wikiPath := models.WikiPath(repoRecord.OwnerName, repoRecord.Name) From d3b6d8355efeda0427a2047338f94b1c89e3a925 Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Tue, 12 Oct 2021 11:44:47 +0800 Subject: [PATCH 4/8] fix the issue about change the cloundbranin status --- templates/repo/cloudbrain/index.tmpl | 34 +++++++++++++++++++++++----------- web_src/less/openi.less | 8 ++++---- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/templates/repo/cloudbrain/index.tmpl b/templates/repo/cloudbrain/index.tmpl index f39e0605a..4021fde97 100755 --- a/templates/repo/cloudbrain/index.tmpl +++ b/templates/repo/cloudbrain/index.tmpl @@ -271,19 +271,28 @@
- + + {{.Status}} + + - {{if eq .Status "STOPPED"}} - 已停止 - {{else if eq .Status "RUNNING"}} - 运行中 - {{else if eq .Status "FAILED"}} - 运行失败 - {{else if eq .Status "WAITING"}} - 初始化等待 - {{end}} {{TimeSinceUnix .Cloudbrain.CreatedUnix $.Lang}}
@@ -456,15 +465,18 @@ $(document).ready(loadJobStatus); function loadJobStatus() { $(".job-status").each((index, job) => { + console.log("---------",index,job) const jobID = job.dataset.jobid; const repoPath = job.dataset.repopath; if (job.textContent.trim() == 'STOPPED') { + return } $.get(`/api/v1/repos/${repoPath}/cloudbrain/${jobID}`, (data) => { const jobID = data.JobID const status = data.JobStatus + console.log("status",status) if (status != job.textContent.trim()) { //$('#' + jobID).text(status) //if (status == 'STOPPED') { diff --git a/web_src/less/openi.less b/web_src/less/openi.less index 521515906..3230a725d 100644 --- a/web_src/less/openi.less +++ b/web_src/less/openi.less @@ -224,15 +224,15 @@ footer .column{margin-bottom:0!important; padding-bottom:0!important;} // icon cloudbrain .i-round{display:inline-block;width:18px;height:18px;background:url("/img/icons.svg");background-position: -496px -52px;} .i-bg-organ{background-position: -496px -52px;} -.i-bg-stop{background-position: -459px -52px;} -.i-bg-running{background-position: -478px -52px;} +.STOPPED{display:inline-block;width:18px;height:18px;background:url("/img/icons.svg");background-position: -496px -52px;background-position: -459px -52px;} +.RUNNING{display:inline-block;width:18px;height:18px;background:url("/img/icons.svg");background-position: -496px -52px;background-position: -478px -52px;} .i-bg-orange{background-position: -495px -51px;} -.i-bg-red{background-position: -532px -52px;} +.FAILED{display:inline-block;width:18px;height:18px;background:url("/img/icons.svg");background-position: -496px -52px;background-position: -532px -52px;} .i-bg-green{background-position: -441px -52px;} .i-bg-used{background-position: -514px -52px;} .icon-bind{background-position: -550px -52px;} .icon-unbind{background-position: -568px -52px;} -.showCircle{display:inline-block;background-image:url('/img/loading.gif');background-repeat:no-repeat;width:16px;height:16px;background-size:16px 16px;margin-right:5px;} +.WAITING{display:inline-block;background-image:url('/img/loading.gif');background-repeat:no-repeat;width:16px;height:16px;background-size:16px 16px;margin-right:5px;} .text_over{ overflow: hidden; text-overflow: ellipsis; From 01ccc47f55c471ee8ec13b58e391fa1ff68c5950 Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Tue, 12 Oct 2021 12:37:50 +0800 Subject: [PATCH 5/8] fix issue fix-327 --- templates/repo/issue/list.tmpl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index a99205eea..9c0be9a71 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -4,18 +4,19 @@
-
{{template "repo/issue/search" .}}
{{if not .Repository.IsArchived}}
- {{template "repo/issue/navbar" .}} + {{if .PageIsIssueList}} {{.i18n.Tr "repo.issues.new"}} {{else}} From e16ab13e1b7fe595fa667cd385ad408d62feb205 Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Tue, 12 Oct 2021 15:19:43 +0800 Subject: [PATCH 6/8] fix issue #487 --- web_src/js/components/EditTopics.vue | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web_src/js/components/EditTopics.vue b/web_src/js/components/EditTopics.vue index c946dff47..5c452d76a 100644 --- a/web_src/js/components/EditTopics.vue +++ b/web_src/js/components/EditTopics.vue @@ -197,13 +197,13 @@ export default { }) }, postTopic(){ - const patter = /^[\u4e00-\u9fa5a-z0-9][\u4e00-\u9fa5a-zA-Z0-9-]{0,35}$/ + const patter = /^[\u4e00-\u9fa5a-zA-Z0-9][\u4e00-\u9fa5a-zA-Z0-9-]{0,34}$/ let regexp = patter.test(this.input) console.log("regexp",regexp) if(!regexp){ this.$notify({ - message: '主题必须以中文、字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符', + message: '标签名必须以中文、字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符', duration: 3000, type:'error' }); From 0726f97ceb30faf9e828c173ef01adee11ca5431 Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Tue, 12 Oct 2021 17:29:27 +0800 Subject: [PATCH 7/8] fix issue #327 about navbar right --- templates/repo/issue/list.tmpl | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/templates/repo/issue/list.tmpl b/templates/repo/issue/list.tmpl index 9c0be9a71..e7cb8b19f 100644 --- a/templates/repo/issue/list.tmpl +++ b/templates/repo/issue/list.tmpl @@ -3,20 +3,14 @@ {{template "repo/header" .}}
-
- - {{template "repo/issue/navbar" .}} +
{{template "repo/issue/search" .}}
{{if not .Repository.IsArchived}}
- + {{template "repo/issue/navbar" .}} {{if .PageIsIssueList}} {{.i18n.Tr "repo.issues.new"}} {{else}} From 6e660c868eaf4eb4e4b270f7f8a87e46f44c32ab Mon Sep 17 00:00:00 2001 From: avadesian Date: Tue, 12 Oct 2021 17:44:44 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E5=A4=84=E7=90=86=E6=8B=89=E5=8F=96?= =?UTF-8?q?=E4=B8=8A=E6=B8=B8=E5=88=86=E6=94=AF=E6=9B=B4=E6=96=B0=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=83=85=E5=86=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- options/locale/locale_en-US.ini | 3 ++- options/locale/locale_zh-CN.ini | 1 + routers/repo/view.go | 41 ++++++++++++++++++++++------------------- templates/repo/home.tmpl | 4 ++++ 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 52e3a50ce..141a6dd65 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -87,7 +87,7 @@ write = Write preview = Preview loading = Loading… -error404_index = Request forbidden by administrative rules +error404_index = Request forbidden by administrative rules error500_index = Internal Server Error error404 = The page you are trying to reach either does not exist or you are not authorized to view it. error500= Sorry, the site has encountered some problems, we are trying to fix the page, please try again later. @@ -1247,6 +1247,7 @@ pulls.commits_count_1=This branch is %d commit behind the upstream. pulls.commits_count_n=This branch is %d commit behind the upstream. pulls.fetch_upstream=Fetch upstream pulls.upstream_up_to_date=No new commits to fetch +pulls.upstream_error=Cannot get upstream info pulls.no_merge_desc = This pull request cannot be merged because all repository merge options are disabled. pulls.no_merge_helper = Enable merge options in the repository settings or merge the pull request manually. diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index 397bcbdb8..5cb62d823 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -1249,6 +1249,7 @@ pulls.commits_count_1=当前分支落后上游分支 %d 个提交 pulls.commits_count_n=当前分支落后上游分支 %d 个提交 pulls.fetch_upstream=拉取上游更新 pulls.upstream_up_to_date=上游分支没有新的更新 +pulls.upstream_error=获取上游分支信息错误 pulls.no_merge_desc=由于未启用合并选项,此合并请求无法被合并。 pulls.no_merge_helper=在项目设置中启用合并选项或者手工合并请求。 diff --git a/routers/repo/view.go b/routers/repo/view.go index 8c768c9eb..0d284c42b 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -799,29 +799,32 @@ func renderCode(ctx *context.Context) { // 3. /{:baseOwner}/{:baseRepoName}/compare/{:baseBranch}...{:headOwner}/{:headRepoName}:{:headBranch} */ baseGitRepo, err := git.OpenRepository(ctx.Repo.Repository.BaseRepo.RepoPath()) + defer baseGitRepo.Close() if err != nil { log.Error("error open baseRepo:%s",ctx.Repo.Repository.BaseRepo.RepoPath()) - } - defer baseGitRepo.Close() - if _,error:= baseGitRepo.GetBranch(ctx.Repo.BranchName);error==nil{ - //base repo has the same branch, then compare between current repo branch and base repo's branch - compareUrl := ctx.Repo.BranchName + "..." + ctx.Repo.Repository.BaseRepo.OwnerName + "/" + ctx.Repo.Repository.BaseRepo.Name + ":" + ctx.Repo.BranchName - ctx.SetParams("*",compareUrl) + ctx.Data["FetchUpstreamCnt"] = -1 // minus value indicates error }else{ - //else, compare between current repo branch and base repo's default branch - compareUrl := ctx.Repo.BranchName + "..." + ctx.Repo.Repository.BaseRepo.OwnerName + "/" + ctx.Repo.Repository.BaseRepo.Name + ":" + ctx.Repo.Repository.BaseRepo.DefaultBranch - ctx.SetParams("*",compareUrl) - } - - _, _, headGitRepo, compareInfo, _, _ := ParseCompareInfo(ctx) - defer headGitRepo.Close() - if compareInfo!= nil { - if compareInfo.Commits!=nil { - log.Info("compareInfoCommits数量:%d",compareInfo.Commits.Len()) - ctx.Data["FetchUpstreamCnt"] = compareInfo.Commits.Len() + if _,error:= baseGitRepo.GetBranch(ctx.Repo.BranchName);error==nil{ + //base repo has the same branch, then compare between current repo branch and base repo's branch + compareUrl := ctx.Repo.BranchName + "..." + ctx.Repo.Repository.BaseRepo.OwnerName + "/" + ctx.Repo.Repository.BaseRepo.Name + ":" + ctx.Repo.BranchName + ctx.SetParams("*",compareUrl) + }else{ + //else, compare between current repo branch and base repo's default branch + compareUrl := ctx.Repo.BranchName + "..." + ctx.Repo.Repository.BaseRepo.OwnerName + "/" + ctx.Repo.Repository.BaseRepo.Name + ":" + ctx.Repo.Repository.BaseRepo.DefaultBranch + ctx.SetParams("*",compareUrl) + } + _, _, headGitRepo, compareInfo, _, _ := ParseCompareInfo(ctx) + defer headGitRepo.Close() + if compareInfo!= nil { + if compareInfo.Commits!=nil { + log.Info("compareInfoCommits数量:%d",compareInfo.Commits.Len()) + ctx.Data["FetchUpstreamCnt"] = compareInfo.Commits.Len() + }else{ + log.Info("compareInfo nothing different") + ctx.Data["FetchUpstreamCnt"] = 0 + } }else{ - log.Info("compareInfo nothing different") - ctx.Data["FetchUpstreamCnt"] = 0 + ctx.Data["FetchUpstreamCnt"] = -1 // minus value indicates error } } } diff --git a/templates/repo/home.tmpl b/templates/repo/home.tmpl index d4a880647..8d52f9115 100644 --- a/templates/repo/home.tmpl +++ b/templates/repo/home.tmpl @@ -159,6 +159,10 @@ + {{else if lt .FetchUpstreamCnt 0}} + + + {{else}}