From 5fc9cd0e502c240e6a30422c0154ccd2b273df4e Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 10 Oct 2023 14:00:09 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E6=96=87=E6=9C=AC=E6=A0=87=E8=AF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/structs/repo_file.go | 1 + services/repository/files/content.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/modules/structs/repo_file.go b/modules/structs/repo_file.go index 5e8bc3c..5059a17 100644 --- a/modules/structs/repo_file.go +++ b/modules/structs/repo_file.go @@ -22,6 +22,7 @@ type BatchFileResponse struct { type ContentsResponse struct { *gitea_api.ContentsResponse + IsTextFile bool `json:"is_text_file"` LatestCommit ContentsResponseCommit `json:"latest_commit"` } diff --git a/services/repository/files/content.go b/services/repository/files/content.go index a92262f..0705b20 100644 --- a/services/repository/files/content.go +++ b/services/repository/files/content.go @@ -11,6 +11,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/git" gitea_api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/typesniffer" "code.gitea.io/gitea/modules/util" gitea_files_service "code.gitea.io/gitea/services/repository/files" hat_api "code.gitlink.org.cn/Gitlink/gitea_hat.git/modules/structs" @@ -134,6 +135,21 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref return nil, err } + blob, err := gitRepo.GetBlob(entry.ID.String()) + if err != nil { + return nil, err + } + dataRc, err := blob.DataAsync() + if err != nil { + return nil, err + } + buf := make([]byte, 1024) + n, _ := util.ReadAtMost(dataRc, buf) + buf = buf[:n] + + st := typesniffer.DetectContentType(buf) + isTextFile := st.IsText() + contentsResponse := &hat_api.ContentsResponse{ ContentsResponse: &gitea_api.ContentsResponse{ Name: entry.Name(), @@ -146,6 +162,7 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref Self: &selfURLString, }, }, + IsTextFile: isTextFile, LatestCommit: hat_api.ContentsResponseCommit{ Message: lastCommit.CommitMessage, Sha: lastCommit.ID.String(), -- 2.34.1 From 749066ec625246b07f9afba70a4312c2fc9725ea Mon Sep 17 00:00:00 2001 From: xxq250 Date: Tue, 10 Oct 2023 16:01:51 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E7=A6=81=E6=AD=A2=E4=B8=AA=E4=BA=BA?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/user/settings/profile.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/user/settings/profile.tmpl b/templates/user/settings/profile.tmpl index 87b6e37..83a537c 100644 --- a/templates/user/settings/profile.tmpl +++ b/templates/user/settings/profile.tmpl @@ -15,7 +15,7 @@ {{.locale.Tr "settings.change_username_prompt"}} {{.locale.Tr "settings.change_username_redirect_prompt"}} - + {{if or (not .SignedUser.IsLocal) .IsReverseProxy}}

{{$.locale.Tr "settings.password_username_disabled"}}

{{end}} -- 2.34.1 From de2fd012711b2d6023db76b0a7de9b3cfba36e92 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 12 Oct 2023 10:24:45 +0800 Subject: [PATCH 3/7] =?UTF-8?q?fixed=20=E5=BD=93=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E4=B8=AD=E6=9C=89=E5=AD=90=E6=A8=A1=E5=9D=97=E5=AD=90=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=B8=94=E6=89=BE=E4=B8=8D=E5=88=B0commitid=E7=9A=84?= =?UTF-8?q?=E6=83=85=E5=86=B5=E4=B8=8B=E6=8A=A5=E9=94=99=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/hat/repo/file.go | 4 ++-- services/repository/files/content.go | 29 +++++++++++++++------------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/routers/hat/repo/file.go b/routers/hat/repo/file.go index f990f12..63007d5 100644 --- a/routers/hat/repo/file.go +++ b/routers/hat/repo/file.go @@ -137,12 +137,12 @@ func GetReadmeContents(ctx *context.APIContext) { readmeSortArr := []string{"readme", "readme.en.md", "readme_en.md", "readme.md", "readme.ch.md", "readme_ch.md", "readme.zh.md", "readme_zh.md", "readme.cn.md", "readme_cn.md"} readmePath := "" readmePathInArrIndex := 0 - filesListInterface, err := files_service.GetContentsOrList(ctx, ctx.Repo.Repository, "", ref) + filesListInterface, err := hat_files_service.GetContentsOrList(ctx, ctx.Repo.Repository, "", ref) if err != nil { ctx.Error(http.StatusInternalServerError, "GetContentsOrList", err) return } - filesList, ok := filesListInterface.([]*api.ContentsResponse) + filesList, ok := filesListInterface.([]*hat_api.ContentsResponse) if ok { for _, file := range filesList { for i, sortItem := range readmeSortArr { diff --git a/services/repository/files/content.go b/services/repository/files/content.go index 0705b20..fee9a61 100644 --- a/services/repository/files/content.go +++ b/services/repository/files/content.go @@ -134,21 +134,24 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref if err != nil { return nil, err } + var isTextFile = false - blob, err := gitRepo.GetBlob(entry.ID.String()) - if err != nil { - return nil, err - } - dataRc, err := blob.DataAsync() - if err != nil { - return nil, err - } - buf := make([]byte, 1024) - n, _ := util.ReadAtMost(dataRc, buf) - buf = buf[:n] + if !entry.IsSubModule() { + blob, err := gitRepo.GetBlob(entry.ID.String()) + if err != nil { + return nil, err + } + dataRc, err := blob.DataAsync() + if err != nil { + return nil, err + } + buf := make([]byte, 1024) + n, _ := util.ReadAtMost(dataRc, buf) + buf = buf[:n] - st := typesniffer.DetectContentType(buf) - isTextFile := st.IsText() + st := typesniffer.DetectContentType(buf) + isTextFile = st.IsText() + } contentsResponse := &hat_api.ContentsResponse{ ContentsResponse: &gitea_api.ContentsResponse{ -- 2.34.1 From c4829333a8859d3db9e7a54892f3429586ed78b7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 11 Dec 2023 08:44:33 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=8F=AA?= =?UTF-8?q?=E6=9C=89email=E4=B8=8D=E6=95=8F=E6=84=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/git/repo_contributors.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/git/repo_contributors.go b/modules/git/repo_contributors.go index e75b532..c2a9c19 100644 --- a/modules/git/repo_contributors.go +++ b/modules/git/repo_contributors.go @@ -119,7 +119,7 @@ func GetRepoContributorsNew(repo *gitea_git.Repository, page, pageSize int) (int return err } name := l[strings.Index(l, "\t")+1 : strings.Index(l, " <")] - email := l[strings.Index(l, "<")+1 : strings.Index(l, ">")] + email := strings.ToLower(l[strings.Index(l, "<")+1 : strings.Index(l, ">")]) totalContributions += commitsInt // committer is not system user if existedContributorInfo, ok := contributorInfoHash[email]; ok { -- 2.34.1 From cc050e9c195004926b0b5b790f9072f807ce6a7c Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 11 Dec 2023 08:49:56 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E6=A0=87=E7=AD=BE=E8=AF=A6=E6=83=85=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/hat/hat.go | 1 + routers/hat/repo/tag.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/routers/hat/hat.go b/routers/hat/hat.go index 539d108..115e0aa 100644 --- a/routers/hat/hat.go +++ b/routers/hat/hat.go @@ -79,6 +79,7 @@ func Routers(ctx gocontext.Context) *web.Route { }, context.ReferencesGitRepo(), reqRepoReader(unit.TypeCode)) m.Group("/tags", func() { m.Get("", repo.ListTags) + m.Get("/*", repo.GetTag) }, reqRepoReader(unit_model.TypeCode), context.ReferencesGitRepo(true)) m.Group("/wikies", func() { m.Combo("").Get(repo.ListWikiPages). diff --git a/routers/hat/repo/tag.go b/routers/hat/repo/tag.go index a0a88dd..260d4a0 100644 --- a/routers/hat/repo/tag.go +++ b/routers/hat/repo/tag.go @@ -44,6 +44,20 @@ func ListTags(ctx *context.APIContext) { ctx.JSON(http.StatusOK, &apiTags) } +func GetTag(ctx *context.APIContext) { + tagName := ctx.Params("*") + tag, err := ctx.Repo.GitRepo.GetTag(tagName) + if err != nil { + ctx.NotFound(tagName) + } + + apiTag, err := convert.ToTag(ctx.Repo.Repository, ctx.Repo.GitRepo, tag) + if err != nil { + ctx.Error(http.StatusInternalServerError, "hat_convert.ToTag", err) + } + ctx.JSON(http.StatusOK, apiTag) +} + func BranchTagCount(ctx *context.APIContext) { _, tagsTotal, err := ctx.Repo.GitRepo.GetTagInfos(0, 0) if err != nil { -- 2.34.1 From 9e0272b872f3efa6dc3d746e1168e494134ae394 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 11 Dec 2023 08:52:15 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Aparams=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=AD=A3=E5=B8=B8=E8=8E=B7=E5=8F=96=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/hat/repo/file.go | 4 ++-- routers/hat/repo/tag.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/routers/hat/repo/file.go b/routers/hat/repo/file.go index 63007d5..1eb5b02 100644 --- a/routers/hat/repo/file.go +++ b/routers/hat/repo/file.go @@ -133,7 +133,7 @@ func GetReadmeContents(ctx *context.APIContext) { return } - ref := ctx.Params(":ref") + ref := ctx.FormString("ref") readmeSortArr := []string{"readme", "readme.en.md", "readme_en.md", "readme.md", "readme.ch.md", "readme_ch.md", "readme.zh.md", "readme_zh.md", "readme.cn.md", "readme_cn.md"} readmePath := "" readmePathInArrIndex := 0 @@ -187,7 +187,7 @@ func GetReadmeContentsByPath(ctx *context.APIContext) { return } treePath := ctx.Params("*") - ref := ctx.Params(":ref") + ref := ctx.FormString("ref") readmeSortArr := []string{"readme", "readme.en.md", "readme_en.md", "readme.md", "readme.ch.md", "readme_ch.md", "readme.zh.md", "readme_zh.md", "readme.cn.md", "readme_cn.md"} readmePath := "" readmePathInArrIndex := 0 diff --git a/routers/hat/repo/tag.go b/routers/hat/repo/tag.go index 260d4a0..b44a52f 100644 --- a/routers/hat/repo/tag.go +++ b/routers/hat/repo/tag.go @@ -80,7 +80,7 @@ func BranchTagCount(ctx *context.APIContext) { func BranchNameSet(ctx *context.APIContext) { - searchName := ctx.Params("name") + searchName := ctx.FormString("name") branches, _, err := ctx.Repo.GitRepo.GetBranchNames(0, 0) //get count of the branch if err != nil { ctx.ServerError("GetBranches", err) @@ -104,7 +104,7 @@ func BranchNameSet(ctx *context.APIContext) { func TagNameSet(ctx *context.APIContext) { - searchName := ctx.Params("name") + searchName := ctx.FormString("name") tags, err := ctx.Repo.GitRepo.GetTags(0, 0) if err != nil { -- 2.34.1 From ee82334a672a44c244edfde58c14c13ac5838213 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 12 Dec 2023 10:16:43 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Adockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 32 ++++++++++++++++++++------------ docker-compose.yml | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 12 deletions(-) create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile index 6a6fa03..571f5db 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,21 @@ -FROM bitnami/git:latest -RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list -RUN apt update -RUN apt install -y vim nano curl wget -RUN wget --no-check-certificate https://go.dev/dl/go1.20.4.linux-amd64.tar.gz -RUN tar -C /usr/local -xzf go1.20.4.linux-amd64.tar.gz -ENV PATH=$PATH:/usr/local/go/bin -RUN go version -RUN go env -w GOPROXY=https://goproxy.cn -ADD ./ /gitea_hat/ -RUN cd /gitea_hat/ && ls -lh && sh build.sh +FROM golang:alpine as build -#/gitea_hat/gitea_hat admin user create --username root --password 123456 --email root@forge.com --admin +ENV GOPROXY https://goproxy.cn + +WORKDIR /app + +COPY . . + +RUN sh build.sh + +FROM gitea/gitea:1.21.0 + +ENV USER git +ENV GITEA_CUSTOM /data/gitea + +VOLUME ["/data"] + +ENTRYPOINT ["/usr/bin/entrypoint"] +CMD ["/bin/s6-svscan", "/etc/s6"] + +COPY --from=build /app/gitea_hat /usr/local/bin/gitea \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..40f165b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +version: '3' +services: + + app: + container_name: gitea_hat + restart: always + build: + context: . + dockerfile: Dockerfile + external_links: + - mysql + volumes: + - /root/gitea:/data + - /etc/timezone:/etc/timezone:ro + - /etc/localtime:/etc/localtime:ro + networks: + - default + - app_net + ports: + - 10082:3000 + depends_on: + - runner + + runner: + container_name: my_runner + image: gitea/act_runner:nightly + restart: always + networks: + - default + - app_net + volumes: + - /var/run/docker.sock:/var/run/docker.sock:rw + environment: + GITEA_INSTANCE_URL: 'http://xxxxxx:10082' # 输入服务地址 + GITEA_RUNNER_REGISTRATION_TOKEN: 'xxx' # 需要gitea中runner token +networks: + app_net: + external: true \ No newline at end of file -- 2.34.1