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 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 { 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/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/file.go b/routers/hat/repo/file.go index f990f12..1eb5b02 100644 --- a/routers/hat/repo/file.go +++ b/routers/hat/repo/file.go @@ -133,16 +133,16 @@ 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 - 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 { @@ -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 a0a88dd..b44a52f 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 { @@ -66,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) @@ -90,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 { diff --git a/services/repository/files/content.go b/services/repository/files/content.go index a92262f..fee9a61 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" @@ -133,6 +134,24 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref if err != nil { return nil, err } + var isTextFile = false + + 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() + } contentsResponse := &hat_api.ContentsResponse{ ContentsResponse: &gitea_api.ContentsResponse{ @@ -146,6 +165,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(), 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}}