From d1bd7be9d31458e300c5d1d49e7d4604768c6b2e Mon Sep 17 00:00:00 2001 From: Andrew Bezold Date: Mon, 8 Jun 2020 14:54:29 -0400 Subject: [PATCH 01/11] Add Get PR Commits API endpoint --- routers/api/v1/api.go | 2 +- routers/api/v1/repo/pull.go | 93 ++++++++++++++++++++++++++++++++++ routers/api/v1/swagger/repo.go | 7 +++ 3 files changed, 101 insertions(+), 1 deletion(-) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 0567c3560c782..548fb307e1fdd 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -813,7 +813,7 @@ func RegisterRoutes(m *macaron.Macaron) { Get(repo.GetPullReviewComments) }) }) - + m.Get("/commits", repo.GetPullRequestCommits) }) }, mustAllowPulls, reqRepoReader(models.UnitTypeCode), context.ReferencesGitRepo(false)) m.Group("/statuses", func() { diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 5acbb9e29709f..502bb70089a62 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -5,8 +5,11 @@ package repo import ( + "container/list" "fmt" + "math" "net/http" + "strconv" "strings" "time" @@ -842,6 +845,96 @@ func MergePullRequest(ctx *context.APIContext, form auth.MergePullRequestForm) { ctx.Status(http.StatusOK) } +// GetPullRequestCommits gets all commits associated with a given PR +func GetPullRequestCommits(ctx *context.APIContext) { + // swagger:operation GET /repos/{owner}/{repo}/pulls/{index}/commits repository repoGetPullRequestCommits + // --- + // summary: Get commits for a pull request + // produces: + // - application/json + // parameters: + // - name: owner + // in: path + // description: owner of the repo + // type: string + // required: true + // - name: repo + // in: path + // description: name of the repo + // type: string + // required: true + // - name: index + // in: path + // description: index of the pull request to get + // type: integer + // format: int64 + // required: true + // - name: page + // in: query + // description: page number of results to return (1-based) + // type: integer + // - name: limit + // in: query + // description: page size of results, maximum page size is 50 + // type: integer + // responses: + // "200": + // "$ref": "#/responses/CommitList" + // "404": + // "$ref": "#/responses/notFound" + // "409": + // "$ref": "#/responses/EmptyPullRequest" + + pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) + if err != nil { + if models.IsErrPullRequestNotExist(err) { + ctx.NotFound() + } else { + ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err) + } + return + } + + var commits *list.List + var prInfo *git.CompareInfo + headGitRepo, err := git.OpenRepository(models.RepoPath(pr.HeadRepo.OwnerName, pr.HeadRepo.Name)) + if err != nil { + ctx.ServerError("OpenRepository", err) + return + } + defer headGitRepo.Close() + prInfo, err = headGitRepo.GetCompareInfo(models.RepoPath(pr.BaseRepo.OwnerName, pr.BaseRepo.Name), pr.BaseBranch, pr.HeadBranch) + if err != nil { + ctx.ServerError("GetCompareInfo", err) + return + } + commits = prInfo.Commits + commits = models.ValidateCommitsWithEmails(commits) + commits = models.ParseCommitsWithSignature(commits, ctx.Repo.Repository) + commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository) + + listOptions := utils.GetListOptions(ctx) + if listOptions.Page <= 0 { + listOptions.Page = 1 + } + + if listOptions.PageSize > git.CommitsRangeSize { + listOptions.PageSize = git.CommitsRangeSize + } + + commitsCount := commits.Len() + pageCount := int(math.Ceil(float64(commitsCount) / float64(listOptions.PageSize))) + + ctx.SetLinkHeader(int(commitsCount), listOptions.PageSize) + + ctx.Header().Set("X-Page", strconv.Itoa(listOptions.Page)) + ctx.Header().Set("X-PerPage", strconv.Itoa(listOptions.PageSize)) + ctx.Header().Set("X-Total", strconv.FormatInt(int64(commitsCount), 10)) + ctx.Header().Set("X-PageCount", strconv.Itoa(pageCount)) + ctx.Header().Set("X-HasMore", strconv.FormatBool(listOptions.Page < pageCount)) + ctx.JSON(http.StatusOK, &commits) +} + func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) (*models.User, *models.Repository, *git.Repository, *git.CompareInfo, string, string) { baseRepo := ctx.Repo.Repository diff --git a/routers/api/v1/swagger/repo.go b/routers/api/v1/swagger/repo.go index bce9e45c379cf..2b6bcd10dcfb7 100644 --- a/routers/api/v1/swagger/repo.go +++ b/routers/api/v1/swagger/repo.go @@ -261,6 +261,13 @@ type swaggerEmptyRepository struct { Body api.APIError `json:"body"` } +// EmptyPullRequest +// swagger:response EmptyPullRequest +type swaggerEmptyPullRequest struct { + //in: body + Body api.APIError `json:"body"` +} + // FileResponse // swagger:response FileResponse type swaggerFileResponse struct { From e8ce20236b8fd7cab59070d223662037f8a5bee7 Mon Sep 17 00:00:00 2001 From: AndrewBezold Date: Tue, 9 Jun 2020 21:45:26 -0400 Subject: [PATCH 02/11] Fix api call --- routers/api/v1/repo/pull.go | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index 502bb70089a62..f88e0f944088f 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -5,7 +5,6 @@ package repo import ( - "container/list" "fmt" "math" "net/http" @@ -895,7 +894,15 @@ func GetPullRequestCommits(ctx *context.APIContext) { return } - var commits *list.List + if err := pr.LoadBaseRepo(); err != nil { + ctx.InternalServerError(err) + return + } + if err := pr.LoadHeadRepo(); err != nil { + ctx.InternalServerError(err) + return + } + var prInfo *git.CompareInfo headGitRepo, err := git.OpenRepository(models.RepoPath(pr.HeadRepo.OwnerName, pr.HeadRepo.Name)) if err != nil { @@ -908,10 +915,7 @@ func GetPullRequestCommits(ctx *context.APIContext) { ctx.ServerError("GetCompareInfo", err) return } - commits = prInfo.Commits - commits = models.ValidateCommitsWithEmails(commits) - commits = models.ParseCommitsWithSignature(commits, ctx.Repo.Repository) - commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository) + commits := prInfo.Commits listOptions := utils.GetListOptions(ctx) if listOptions.Page <= 0 { @@ -925,6 +929,24 @@ func GetPullRequestCommits(ctx *context.APIContext) { commitsCount := commits.Len() pageCount := int(math.Ceil(float64(commitsCount) / float64(listOptions.PageSize))) + userCache := make(map[string]*models.User) + + apiCommits := make([]*api.Commit, commits.Len()) + + i := 0 + for commitPointer := commits.Front(); commitPointer != nil; commitPointer = commitPointer.Next() { + commit := commitPointer.Value.(*git.Commit) + + // Create json struct + apiCommits[i], err = toCommit(ctx, ctx.Repo.Repository, commit, userCache) + if err != nil { + ctx.ServerError("toCommit", err) + return + } + + i++ + } + ctx.SetLinkHeader(int(commitsCount), listOptions.PageSize) ctx.Header().Set("X-Page", strconv.Itoa(listOptions.Page)) @@ -932,7 +954,7 @@ func GetPullRequestCommits(ctx *context.APIContext) { ctx.Header().Set("X-Total", strconv.FormatInt(int64(commitsCount), 10)) ctx.Header().Set("X-PageCount", strconv.Itoa(pageCount)) ctx.Header().Set("X-HasMore", strconv.FormatBool(listOptions.Page < pageCount)) - ctx.JSON(http.StatusOK, &commits) + ctx.JSON(http.StatusOK, &apiCommits) } func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) (*models.User, *models.Repository, *git.Repository, *git.CompareInfo, string, string) { From af0263a49face7453c3eb88495ac13c3a22bffc4 Mon Sep 17 00:00:00 2001 From: AndrewBezold Date: Tue, 9 Jun 2020 21:49:50 -0400 Subject: [PATCH 03/11] Remove unused code --- routers/api/v1/repo/pull.go | 2 -- routers/api/v1/swagger/repo.go | 7 ------- 2 files changed, 9 deletions(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index f88e0f944088f..c4889b88da9f2 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -881,8 +881,6 @@ func GetPullRequestCommits(ctx *context.APIContext) { // "$ref": "#/responses/CommitList" // "404": // "$ref": "#/responses/notFound" - // "409": - // "$ref": "#/responses/EmptyPullRequest" pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index")) if err != nil { diff --git a/routers/api/v1/swagger/repo.go b/routers/api/v1/swagger/repo.go index 2b6bcd10dcfb7..bce9e45c379cf 100644 --- a/routers/api/v1/swagger/repo.go +++ b/routers/api/v1/swagger/repo.go @@ -261,13 +261,6 @@ type swaggerEmptyRepository struct { Body api.APIError `json:"body"` } -// EmptyPullRequest -// swagger:response EmptyPullRequest -type swaggerEmptyPullRequest struct { - //in: body - Body api.APIError `json:"body"` -} - // FileResponse // swagger:response FileResponse type swaggerFileResponse struct { From 089f4b6f299c40d83ab9a4698a1897d394513bb1 Mon Sep 17 00:00:00 2001 From: Andrew Bezold Date: Mon, 29 Jun 2020 14:50:36 -0400 Subject: [PATCH 04/11] Add repo for PR testing --- .../user2/pr_repo.git/FETCH_HEAD | 1 + .../user2/pr_repo.git/HEAD | 1 + .../user2/pr_repo.git/config | 6 + .../user2/pr_repo.git/description | 1 + .../pr_repo.git/hooks/applypatch-msg.sample | 15 ++ .../user2/pr_repo.git/hooks/commit-msg.sample | 24 +++ .../hooks/fsmonitor-watchman.sample | 114 ++++++++++++ .../user2/pr_repo.git/hooks/post-receive | 15 ++ .../pr_repo.git/hooks/post-receive.d/gitea | 2 + .../pr_repo.git/hooks/post-update.sample | 8 + .../pr_repo.git/hooks/pre-applypatch.sample | 14 ++ .../user2/pr_repo.git/hooks/pre-commit.sample | 49 +++++ .../user2/pr_repo.git/hooks/pre-push.sample | 53 ++++++ .../user2/pr_repo.git/hooks/pre-rebase.sample | 169 ++++++++++++++++++ .../user2/pr_repo.git/hooks/pre-receive | 15 ++ .../pr_repo.git/hooks/pre-receive.d/gitea | 2 + .../pr_repo.git/hooks/pre-receive.sample | 24 +++ .../hooks/prepare-commit-msg.sample | 42 +++++ .../user2/pr_repo.git/hooks/update | 14 ++ .../user2/pr_repo.git/hooks/update.d/gitea | 2 + .../user2/pr_repo.git/hooks/update.sample | 128 +++++++++++++ .../user2/pr_repo.git/info/exclude | 6 + .../user2/pr_repo.git/info/refs | 7 + .../07/13475aeb24731bf654b5ffb2b0249e9eab6990 | Bin 0 -> 158 bytes .../0a/2d4136a3bddf08e911a3ec15084ba40854e0a9 | Bin 0 -> 132 bytes .../20/55bdadcecdb500439ac40d578d22bae519bbd5 | 3 + .../26/fe6b8214e5a81552c65afb352423c75d45f224 | Bin 0 -> 42 bytes .../36/b3272824712ce55a1a54623fa60b85cb7b164f | Bin 0 -> 54 bytes .../37/ee6d4188640579b9b6c76f5f262c95370464fc | Bin 0 -> 54 bytes .../3e/b36aca1a9d0ebcc52e54e190352b206104fe9f | Bin 0 -> 54 bytes .../44/3bb80f40ada270ea0d8b9df4ce7f1173a5748a | Bin 0 -> 158 bytes .../5c/d799fa19eb2e82145ed8211598ec3cb947046e | Bin 0 -> 54 bytes .../5e/44474e4d747248ad46b7d90f368f3b0582de64 | Bin 0 -> 54 bytes .../71/ef50ba32849b9b7b4d8c98dd98f5a68134c62f | 3 + .../9b/42fd4bde301c8762baafb8c9b77b56aa63bc48 | Bin 0 -> 54 bytes .../9b/63ac63a3e121ef77e8f046c8521d77a7171d35 | Bin 0 -> 75 bytes .../a2/0333be2715060c61c8d0268c4f622bde1ae4ac | Bin 0 -> 158 bytes .../b1/715a6bdacfab4bbfa6c7a58f970b7ca7476b20 | Bin 0 -> 54 bytes .../c2/e48d686876138b9a5ba7f260d3827a208409fa | 1 + .../c7/11aebdd140cebd540469c0de87960457a0ab81 | 2 + .../d0/b367de3c539d0d37e0c1b1acaf90c83c66aad4 | Bin 0 -> 54 bytes .../d2/44ac23bcd16c640ff10e29f70cb9c79c928c56 | Bin 0 -> 54 bytes .../dd/9b2bfb61431f03357972975ae8b0c68c6770df | 1 + .../e1/adcf142a07305ebf40590a41b1a279486759db | 3 + .../e3/dfaeb234e2a4570875ea3be7cedaebf350d703 | 2 + .../e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 | Bin 0 -> 15 bytes .../f3/5a7427dd78d730782bc51d73be2d919ca35810 | Bin 0 -> 61 bytes .../f6/11a4c2dc1894ebbe5e8b558b4055169506048b | 2 + .../f6/211fabb4e7f31f76b64dda1aa8545ff7eb2e78 | Bin 0 -> 158 bytes .../f6/3107991a7971d7953be3b96d735cafc576620b | Bin 0 -> 90 bytes .../f9/3e3a1a1525fb5b91020da86e44810c87a2d7bc | Bin 0 -> 54 bytes .../fe/78eda57d408e7c7f44e97ed68a2213c9ba63e9 | 1 + .../ff/3bd934908fed79bfd11cc3c1edaeec694a58d2 | Bin 0 -> 96 bytes .../ff/f2d8fe1b36ec3ababaa45266ea4bcfda303858 | Bin 0 -> 59 bytes .../user2/pr_repo.git/objects/info/packs | 1 + .../user2/pr_repo.git/packed-refs | 1 + .../user2/pr_repo.git/refs/heads/closed_pr | 1 + .../user2/pr_repo.git/refs/heads/master | 1 + .../user2/pr_repo.git/refs/heads/merged_pr | 1 + .../user2/pr_repo.git/refs/heads/open_pr | 1 + .../user2/pr_repo.git/refs/pull/1/head | 1 + .../user2/pr_repo.git/refs/pull/2/head | 1 + .../user2/pr_repo.git/refs/pull/3/head | 1 + 63 files changed, 739 insertions(+) create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/FETCH_HEAD create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/HEAD create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/config create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/description create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/applypatch-msg.sample create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/commit-msg.sample create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/fsmonitor-watchman.sample create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-receive create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-receive.d/gitea create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-update.sample create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-applypatch.sample create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-commit.sample create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-push.sample create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-rebase.sample create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive.d/gitea create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive.sample create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/prepare-commit-msg.sample create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update.d/gitea create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update.sample create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/info/exclude create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/info/refs create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/07/13475aeb24731bf654b5ffb2b0249e9eab6990 create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/0a/2d4136a3bddf08e911a3ec15084ba40854e0a9 create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/20/55bdadcecdb500439ac40d578d22bae519bbd5 create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/26/fe6b8214e5a81552c65afb352423c75d45f224 create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/36/b3272824712ce55a1a54623fa60b85cb7b164f create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/37/ee6d4188640579b9b6c76f5f262c95370464fc create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/3e/b36aca1a9d0ebcc52e54e190352b206104fe9f create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/44/3bb80f40ada270ea0d8b9df4ce7f1173a5748a create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/5c/d799fa19eb2e82145ed8211598ec3cb947046e create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/5e/44474e4d747248ad46b7d90f368f3b0582de64 create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/71/ef50ba32849b9b7b4d8c98dd98f5a68134c62f create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/9b/42fd4bde301c8762baafb8c9b77b56aa63bc48 create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/9b/63ac63a3e121ef77e8f046c8521d77a7171d35 create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/a2/0333be2715060c61c8d0268c4f622bde1ae4ac create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/b1/715a6bdacfab4bbfa6c7a58f970b7ca7476b20 create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/c2/e48d686876138b9a5ba7f260d3827a208409fa create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/c7/11aebdd140cebd540469c0de87960457a0ab81 create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/d0/b367de3c539d0d37e0c1b1acaf90c83c66aad4 create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/d2/44ac23bcd16c640ff10e29f70cb9c79c928c56 create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/dd/9b2bfb61431f03357972975ae8b0c68c6770df create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/e1/adcf142a07305ebf40590a41b1a279486759db create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/e3/dfaeb234e2a4570875ea3be7cedaebf350d703 create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f3/5a7427dd78d730782bc51d73be2d919ca35810 create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f6/11a4c2dc1894ebbe5e8b558b4055169506048b create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f6/211fabb4e7f31f76b64dda1aa8545ff7eb2e78 create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f6/3107991a7971d7953be3b96d735cafc576620b create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f9/3e3a1a1525fb5b91020da86e44810c87a2d7bc create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/fe/78eda57d408e7c7f44e97ed68a2213c9ba63e9 create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/ff/3bd934908fed79bfd11cc3c1edaeec694a58d2 create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/ff/f2d8fe1b36ec3ababaa45266ea4bcfda303858 create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/objects/info/packs create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/packed-refs create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/closed_pr create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/master create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/merged_pr create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/open_pr create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/1/head create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/2/head create mode 100644 integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/3/head diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/FETCH_HEAD b/integrations/gitea-repositories-meta/user2/pr_repo.git/FETCH_HEAD new file mode 100644 index 0000000000000..85e186d580052 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/FETCH_HEAD @@ -0,0 +1 @@ +71ef50ba32849b9b7b4d8c98dd98f5a68134c62f branch 'master' of C:\other\gitea-repositories\user2\pr_repo diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/HEAD b/integrations/gitea-repositories-meta/user2/pr_repo.git/HEAD new file mode 100644 index 0000000000000..cb089cd89a7d7 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/config b/integrations/gitea-repositories-meta/user2/pr_repo.git/config new file mode 100644 index 0000000000000..64280b806c976 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/config @@ -0,0 +1,6 @@ +[core] + repositoryformatversion = 0 + filemode = false + bare = true + symlinks = false + ignorecase = true diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/description b/integrations/gitea-repositories-meta/user2/pr_repo.git/description new file mode 100644 index 0000000000000..498b267a8c781 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/applypatch-msg.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/applypatch-msg.sample new file mode 100644 index 0000000000000..a5d7b84a67345 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/applypatch-msg.sample @@ -0,0 +1,15 @@ +#!/bin/sh +# +# An example hook script to check the commit log message taken by +# applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. The hook is +# allowed to edit the commit message file. +# +# To enable this hook, rename this file to "applypatch-msg". + +. git-sh-setup +commitmsg="$(git rev-parse --git-path hooks/commit-msg)" +test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"} +: diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/commit-msg.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/commit-msg.sample new file mode 100644 index 0000000000000..b58d1184a9d43 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/commit-msg.sample @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to check the commit log message. +# Called by "git commit" with one argument, the name of the file +# that has the commit message. The hook should exit with non-zero +# status after issuing an appropriate message if it wants to stop the +# commit. The hook is allowed to edit the commit message file. +# +# To enable this hook, rename this file to "commit-msg". + +# Uncomment the below to add a Signed-off-by line to the message. +# Doing this in a hook is a bad idea in general, but the prepare-commit-msg +# hook is more suited to it. +# +# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" + +# This example catches duplicate Signed-off-by lines. + +test "" = "$(grep '^Signed-off-by: ' "$1" | + sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { + echo >&2 Duplicate Signed-off-by lines. + exit 1 +} diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/fsmonitor-watchman.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/fsmonitor-watchman.sample new file mode 100644 index 0000000000000..e673bb3980f3c --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/fsmonitor-watchman.sample @@ -0,0 +1,114 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use IPC::Open2; + +# An example hook script to integrate Watchman +# (https://facebook.github.io/watchman/) with git to speed up detecting +# new and modified files. +# +# The hook is passed a version (currently 1) and a time in nanoseconds +# formatted as a string and outputs to stdout all files that have been +# modified since the given time. Paths must be relative to the root of +# the working tree and separated by a single NUL. +# +# To enable this hook, rename this file to "query-watchman" and set +# 'git config core.fsmonitor .git/hooks/query-watchman' +# +my ($version, $time) = @ARGV; + +# Check the hook interface version + +if ($version == 1) { + # convert nanoseconds to seconds + $time = int $time / 1000000000; +} else { + die "Unsupported query-fsmonitor hook version '$version'.\n" . + "Falling back to scanning...\n"; +} + +my $git_work_tree; +if ($^O =~ 'msys' || $^O =~ 'cygwin') { + $git_work_tree = Win32::GetCwd(); + $git_work_tree =~ tr/\\/\//; +} else { + require Cwd; + $git_work_tree = Cwd::cwd(); +} + +my $retry = 1; + +launch_watchman(); + +sub launch_watchman { + + my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty') + or die "open2() failed: $!\n" . + "Falling back to scanning...\n"; + + # In the query expression below we're asking for names of files that + # changed since $time but were not transient (ie created after + # $time but no longer exist). + # + # To accomplish this, we're using the "since" generator to use the + # recency index to select candidate nodes and "fields" to limit the + # output to file names only. Then we're using the "expression" term to + # further constrain the results. + # + # The category of transient files that we want to ignore will have a + # creation clock (cclock) newer than $time_t value and will also not + # currently exist. + + my $query = <<" END"; + ["query", "$git_work_tree", { + "since": $time, + "fields": ["name"], + "expression": ["not", ["allof", ["since", $time, "cclock"], ["not", "exists"]]] + }] + END + + print CHLD_IN $query; + close CHLD_IN; + my $response = do {local $/; }; + + die "Watchman: command returned no output.\n" . + "Falling back to scanning...\n" if $response eq ""; + die "Watchman: command returned invalid output: $response\n" . + "Falling back to scanning...\n" unless $response =~ /^\{/; + + my $json_pkg; + eval { + require JSON::XS; + $json_pkg = "JSON::XS"; + 1; + } or do { + require JSON::PP; + $json_pkg = "JSON::PP"; + }; + + my $o = $json_pkg->new->utf8->decode($response); + + if ($retry > 0 and $o->{error} and $o->{error} =~ m/unable to resolve root .* directory (.*) is not watched/) { + print STDERR "Adding '$git_work_tree' to watchman's watch list.\n"; + $retry--; + qx/watchman watch "$git_work_tree"/; + die "Failed to make watchman watch '$git_work_tree'.\n" . + "Falling back to scanning...\n" if $? != 0; + + # Watchman will always return all files on the first query so + # return the fast "everything is dirty" flag to git and do the + # Watchman query just to get it over with now so we won't pay + # the cost in git to look up each individual file. + print "/\0"; + eval { launch_watchman() }; + exit 0; + } + + die "Watchman: $o->{error}.\n" . + "Falling back to scanning...\n" if $o->{error}; + + binmode STDOUT, ":utf8"; + local $, = "\0"; + print @{$o->{files}}; +} diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-receive b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-receive new file mode 100644 index 0000000000000..f1f2709dddeea --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-receive @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +data=$(cat) +exitcodes="" +hookname=$(basename $0) +GIT_DIR=${GIT_DIR:-$(dirname $0)} + +for hook in ${GIT_DIR}/hooks/${hookname}.d/*; do +test -x "${hook}" && test -f "${hook}" || continue +echo "${data}" | "${hook}" +exitcodes="${exitcodes} $?" +done + +for i in ${exitcodes}; do +[ ${i} -eq 0 ] || exit ${i} +done diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-receive.d/gitea b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-receive.d/gitea new file mode 100644 index 0000000000000..bc7fb0a76a319 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-receive.d/gitea @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +"C:/other/gitea/gitea.exe" hook --config='C:/other/gitea/custom/conf/app.ini' post-receive diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-update.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-update.sample new file mode 100644 index 0000000000000..ec17ec1939b7c --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/post-update.sample @@ -0,0 +1,8 @@ +#!/bin/sh +# +# An example hook script to prepare a packed repository for use over +# dumb transports. +# +# To enable this hook, rename this file to "post-update". + +exec git update-server-info diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-applypatch.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-applypatch.sample new file mode 100644 index 0000000000000..4142082bcb939 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-applypatch.sample @@ -0,0 +1,14 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed +# by applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-applypatch". + +. git-sh-setup +precommit="$(git rev-parse --git-path hooks/pre-commit)" +test -x "$precommit" && exec "$precommit" ${1+"$@"} +: diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-commit.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-commit.sample new file mode 100644 index 0000000000000..6a756416384c2 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-commit.sample @@ -0,0 +1,49 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git commit" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message if +# it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-commit". + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=$(git hash-object -t tree /dev/null) +fi + +# If you want to allow non-ASCII filenames set this variable to true. +allownonascii=$(git config --bool hooks.allownonascii) + +# Redirect output to stderr. +exec 1>&2 + +# Cross platform projects tend to avoid non-ASCII filenames; prevent +# them from being added to the repository. We exploit the fact that the +# printable range starts at the space character and ends with tilde. +if [ "$allownonascii" != "true" ] && + # Note that the use of brackets around a tr range is ok here, (it's + # even required, for portability to Solaris 10's /usr/bin/tr), since + # the square bracket bytes happen to fall in the designated range. + test $(git diff --cached --name-only --diff-filter=A -z $against | + LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 +then + cat <<\EOF +Error: Attempt to add a non-ASCII file name. + +This can cause problems if you want to work with people on other platforms. + +To be portable it is advisable to rename the file. + +If you know what you are doing you can disable this check using: + + git config hooks.allownonascii true +EOF + exit 1 +fi + +# If there are whitespace errors, print the offending file names and fail. +exec git diff-index --check --cached $against -- diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-push.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-push.sample new file mode 100644 index 0000000000000..6187dbf4390fc --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-push.sample @@ -0,0 +1,53 @@ +#!/bin/sh + +# An example hook script to verify what is about to be pushed. Called by "git +# push" after it has checked the remote status, but before anything has been +# pushed. If this script exits with a non-zero status nothing will be pushed. +# +# This hook is called with the following parameters: +# +# $1 -- Name of the remote to which the push is being done +# $2 -- URL to which the push is being done +# +# If pushing without using a named remote those arguments will be equal. +# +# Information about the commits which are being pushed is supplied as lines to +# the standard input in the form: +# +# +# +# This sample shows how to prevent push of commits where the log message starts +# with "WIP" (work in progress). + +remote="$1" +url="$2" + +z40=0000000000000000000000000000000000000000 + +while read local_ref local_sha remote_ref remote_sha +do + if [ "$local_sha" = $z40 ] + then + # Handle delete + : + else + if [ "$remote_sha" = $z40 ] + then + # New branch, examine all commits + range="$local_sha" + else + # Update to existing branch, examine new commits + range="$remote_sha..$local_sha" + fi + + # Check for WIP commit + commit=`git rev-list -n 1 --grep '^WIP' "$range"` + if [ -n "$commit" ] + then + echo >&2 "Found WIP commit in $local_ref, not pushing" + exit 1 + fi + fi +done + +exit 0 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-rebase.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-rebase.sample new file mode 100644 index 0000000000000..6cbef5c370d8c --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-rebase.sample @@ -0,0 +1,169 @@ +#!/bin/sh +# +# Copyright (c) 2006, 2008 Junio C Hamano +# +# The "pre-rebase" hook is run just before "git rebase" starts doing +# its job, and can prevent the command from running by exiting with +# non-zero status. +# +# The hook is called with the following parameters: +# +# $1 -- the upstream the series was forked from. +# $2 -- the branch being rebased (or empty when rebasing the current branch). +# +# This sample shows how to prevent topic branches that are already +# merged to 'next' branch from getting rebased, because allowing it +# would result in rebasing already published history. + +publish=next +basebranch="$1" +if test "$#" = 2 +then + topic="refs/heads/$2" +else + topic=`git symbolic-ref HEAD` || + exit 0 ;# we do not interrupt rebasing detached HEAD +fi + +case "$topic" in +refs/heads/??/*) + ;; +*) + exit 0 ;# we do not interrupt others. + ;; +esac + +# Now we are dealing with a topic branch being rebased +# on top of master. Is it OK to rebase it? + +# Does the topic really exist? +git show-ref -q "$topic" || { + echo >&2 "No such branch $topic" + exit 1 +} + +# Is topic fully merged to master? +not_in_master=`git rev-list --pretty=oneline ^master "$topic"` +if test -z "$not_in_master" +then + echo >&2 "$topic is fully merged to master; better remove it." + exit 1 ;# we could allow it, but there is no point. +fi + +# Is topic ever merged to next? If so you should not be rebasing it. +only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` +only_next_2=`git rev-list ^master ${publish} | sort` +if test "$only_next_1" = "$only_next_2" +then + not_in_topic=`git rev-list "^$topic" master` + if test -z "$not_in_topic" + then + echo >&2 "$topic is already up to date with master" + exit 1 ;# we could allow it, but there is no point. + else + exit 0 + fi +else + not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` + /usr/bin/perl -e ' + my $topic = $ARGV[0]; + my $msg = "* $topic has commits already merged to public branch:\n"; + my (%not_in_next) = map { + /^([0-9a-f]+) /; + ($1 => 1); + } split(/\n/, $ARGV[1]); + for my $elem (map { + /^([0-9a-f]+) (.*)$/; + [$1 => $2]; + } split(/\n/, $ARGV[2])) { + if (!exists $not_in_next{$elem->[0]}) { + if ($msg) { + print STDERR $msg; + undef $msg; + } + print STDERR " $elem->[1]\n"; + } + } + ' "$topic" "$not_in_next" "$not_in_master" + exit 1 +fi + +<<\DOC_END + +This sample hook safeguards topic branches that have been +published from being rewound. + +The workflow assumed here is: + + * Once a topic branch forks from "master", "master" is never + merged into it again (either directly or indirectly). + + * Once a topic branch is fully cooked and merged into "master", + it is deleted. If you need to build on top of it to correct + earlier mistakes, a new topic branch is created by forking at + the tip of the "master". This is not strictly necessary, but + it makes it easier to keep your history simple. + + * Whenever you need to test or publish your changes to topic + branches, merge them into "next" branch. + +The script, being an example, hardcodes the publish branch name +to be "next", but it is trivial to make it configurable via +$GIT_DIR/config mechanism. + +With this workflow, you would want to know: + +(1) ... if a topic branch has ever been merged to "next". Young + topic branches can have stupid mistakes you would rather + clean up before publishing, and things that have not been + merged into other branches can be easily rebased without + affecting other people. But once it is published, you would + not want to rewind it. + +(2) ... if a topic branch has been fully merged to "master". + Then you can delete it. More importantly, you should not + build on top of it -- other people may already want to + change things related to the topic as patches against your + "master", so if you need further changes, it is better to + fork the topic (perhaps with the same name) afresh from the + tip of "master". + +Let's look at this example: + + o---o---o---o---o---o---o---o---o---o "next" + / / / / + / a---a---b A / / + / / / / + / / c---c---c---c B / + / / / \ / + / / / b---b C \ / + / / / / \ / + ---o---o---o---o---o---o---o---o---o---o---o "master" + + +A, B and C are topic branches. + + * A has one fix since it was merged up to "next". + + * B has finished. It has been fully merged up to "master" and "next", + and is ready to be deleted. + + * C has not merged to "next" at all. + +We would want to allow C to be rebased, refuse A, and encourage +B to be deleted. + +To compute (1): + + git rev-list ^master ^topic next + git rev-list ^master next + + if these match, topic has not merged in next at all. + +To compute (2): + + git rev-list master..topic + + if this is empty, it is fully merged to "master". + +DOC_END diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive new file mode 100644 index 0000000000000..f1f2709dddeea --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +data=$(cat) +exitcodes="" +hookname=$(basename $0) +GIT_DIR=${GIT_DIR:-$(dirname $0)} + +for hook in ${GIT_DIR}/hooks/${hookname}.d/*; do +test -x "${hook}" && test -f "${hook}" || continue +echo "${data}" | "${hook}" +exitcodes="${exitcodes} $?" +done + +for i in ${exitcodes}; do +[ ${i} -eq 0 ] || exit ${i} +done diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive.d/gitea b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive.d/gitea new file mode 100644 index 0000000000000..abf00a79ea9b2 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive.d/gitea @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +"C:/other/gitea/gitea.exe" hook --config='C:/other/gitea/custom/conf/app.ini' pre-receive diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive.sample new file mode 100644 index 0000000000000..a1fd29ec14823 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/pre-receive.sample @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to make use of push options. +# The example simply echoes all push options that start with 'echoback=' +# and rejects all pushes when the "reject" push option is used. +# +# To enable this hook, rename this file to "pre-receive". + +if test -n "$GIT_PUSH_OPTION_COUNT" +then + i=0 + while test "$i" -lt "$GIT_PUSH_OPTION_COUNT" + do + eval "value=\$GIT_PUSH_OPTION_$i" + case "$value" in + echoback=*) + echo "echo from the pre-receive-hook: ${value#*=}" >&2 + ;; + reject) + exit 1 + esac + i=$((i + 1)) + done +fi diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/prepare-commit-msg.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/prepare-commit-msg.sample new file mode 100644 index 0000000000000..10fa14c5ab013 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/prepare-commit-msg.sample @@ -0,0 +1,42 @@ +#!/bin/sh +# +# An example hook script to prepare the commit log message. +# Called by "git commit" with the name of the file that has the +# commit message, followed by the description of the commit +# message's source. The hook's purpose is to edit the commit +# message file. If the hook fails with a non-zero status, +# the commit is aborted. +# +# To enable this hook, rename this file to "prepare-commit-msg". + +# This hook includes three examples. The first one removes the +# "# Please enter the commit message..." help message. +# +# The second includes the output of "git diff --name-status -r" +# into the message, just before the "git status" output. It is +# commented because it doesn't cope with --amend or with squashed +# commits. +# +# The third example adds a Signed-off-by line to the message, that can +# still be edited. This is rarely a good idea. + +COMMIT_MSG_FILE=$1 +COMMIT_SOURCE=$2 +SHA1=$3 + +/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE" + +# case "$COMMIT_SOURCE,$SHA1" in +# ,|template,) +# /usr/bin/perl -i.bak -pe ' +# print "\n" . `git diff --cached --name-status -r` +# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;; +# *) ;; +# esac + +# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE" +# if test -z "$COMMIT_SOURCE" +# then +# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE" +# fi diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update new file mode 100644 index 0000000000000..df5bd27f106f2 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +exitcodes="" +hookname=$(basename $0) +GIT_DIR=${GIT_DIR:-$(dirname $0)} + +for hook in ${GIT_DIR}/hooks/${hookname}.d/*; do +test -x "${hook}" && test -f "${hook}" || continue +"${hook}" $1 $2 $3 +exitcodes="${exitcodes} $?" +done + +for i in ${exitcodes}; do +[ ${i} -eq 0 ] || exit ${i} +done diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update.d/gitea b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update.d/gitea new file mode 100644 index 0000000000000..79c2d208a2e38 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update.d/gitea @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +"C:/other/gitea/gitea.exe" hook --config='C:/other/gitea/custom/conf/app.ini' update $1 $2 $3 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update.sample b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update.sample new file mode 100644 index 0000000000000..80ba94135cc37 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/hooks/update.sample @@ -0,0 +1,128 @@ +#!/bin/sh +# +# An example hook script to block unannotated tags from entering. +# Called by "git receive-pack" with arguments: refname sha1-old sha1-new +# +# To enable this hook, rename this file to "update". +# +# Config +# ------ +# hooks.allowunannotated +# This boolean sets whether unannotated tags will be allowed into the +# repository. By default they won't be. +# hooks.allowdeletetag +# This boolean sets whether deleting tags will be allowed in the +# repository. By default they won't be. +# hooks.allowmodifytag +# This boolean sets whether a tag may be modified after creation. By default +# it won't be. +# hooks.allowdeletebranch +# This boolean sets whether deleting branches will be allowed in the +# repository. By default they won't be. +# hooks.denycreatebranch +# This boolean sets whether remotely creating branches will be denied +# in the repository. By default this is allowed. +# + +# --- Command line +refname="$1" +oldrev="$2" +newrev="$3" + +# --- Safety check +if [ -z "$GIT_DIR" ]; then + echo "Don't run this script from the command line." >&2 + echo " (if you want, you could supply GIT_DIR then run" >&2 + echo " $0 )" >&2 + exit 1 +fi + +if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then + echo "usage: $0 " >&2 + exit 1 +fi + +# --- Config +allowunannotated=$(git config --bool hooks.allowunannotated) +allowdeletebranch=$(git config --bool hooks.allowdeletebranch) +denycreatebranch=$(git config --bool hooks.denycreatebranch) +allowdeletetag=$(git config --bool hooks.allowdeletetag) +allowmodifytag=$(git config --bool hooks.allowmodifytag) + +# check for no description +projectdesc=$(sed -e '1q' "$GIT_DIR/description") +case "$projectdesc" in +"Unnamed repository"* | "") + echo "*** Project description file hasn't been set" >&2 + exit 1 + ;; +esac + +# --- Check types +# if $newrev is 0000...0000, it's a commit to delete a ref. +zero="0000000000000000000000000000000000000000" +if [ "$newrev" = "$zero" ]; then + newrev_type=delete +else + newrev_type=$(git cat-file -t $newrev) +fi + +case "$refname","$newrev_type" in + refs/tags/*,commit) + # un-annotated tag + short_refname=${refname##refs/tags/} + if [ "$allowunannotated" != "true" ]; then + echo "*** The un-annotated tag, $short_refname, is not allowed in this repository" >&2 + echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 + exit 1 + fi + ;; + refs/tags/*,delete) + # delete tag + if [ "$allowdeletetag" != "true" ]; then + echo "*** Deleting a tag is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/tags/*,tag) + # annotated tag + if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 + then + echo "*** Tag '$refname' already exists." >&2 + echo "*** Modifying a tag is not allowed in this repository." >&2 + exit 1 + fi + ;; + refs/heads/*,commit) + # branch + if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then + echo "*** Creating a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/heads/*,delete) + # delete branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/remotes/*,commit) + # tracking branch + ;; + refs/remotes/*,delete) + # delete tracking branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a tracking branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + *) + # Anything else (is there anything else?) + echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 + exit 1 + ;; +esac + +# --- Finished +exit 0 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/info/exclude b/integrations/gitea-repositories-meta/user2/pr_repo.git/info/exclude new file mode 100644 index 0000000000000..a5196d1be8fb5 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/info/exclude @@ -0,0 +1,6 @@ +# git ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +# *.[oa] +# *~ diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/info/refs b/integrations/gitea-repositories-meta/user2/pr_repo.git/info/refs new file mode 100644 index 0000000000000..e437b259af60b --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/info/refs @@ -0,0 +1,7 @@ +0713475aeb24731bf654b5ffb2b0249e9eab6990 refs/heads/closed_pr +71ef50ba32849b9b7b4d8c98dd98f5a68134c62f refs/heads/master +2055bdadcecdb500439ac40d578d22bae519bbd5 refs/heads/merged_pr +c711aebdd140cebd540469c0de87960457a0ab81 refs/heads/open_pr +c711aebdd140cebd540469c0de87960457a0ab81 refs/pull/1/head +e3dfaeb234e2a4570875ea3be7cedaebf350d703 refs/pull/2/head +f611a4c2dc1894ebbe5e8b558b4055169506048b refs/pull/3/head diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/07/13475aeb24731bf654b5ffb2b0249e9eab6990 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/07/13475aeb24731bf654b5ffb2b0249e9eab6990 new file mode 100644 index 0000000000000000000000000000000000000000..6f3bedbad9e1110fee4e50effe3721c4862f3067 GIT binary patch literal 158 zcmV;P0Ac@l0i}*x3c@fD0R7G>_5zkXcJlxc^(J|2v0xf$BZ8;56mQ_?%*Qaf)jD<1 zCLH?048(}&kg+&)8htEilPf`v#`@7DNnRJWD4ucQxx;9cikNlD$_M0>nAj&GpHLDh z8%SD-K8g71_qM=wE(^cm#-H{maEdz)X~)Ytapid(a;s-h6bzD8mf$E+O0n5(wew$* MUj>Z#0-r}qoKjm%5dZ)H literal 0 HcmV?d00001 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/0a/2d4136a3bddf08e911a3ec15084ba40854e0a9 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/0a/2d4136a3bddf08e911a3ec15084ba40854e0a9 new file mode 100644 index 0000000000000000000000000000000000000000..a250c46c313a75be1bae552549a22350e30e2fdd GIT binary patch literal 132 zcmV-~0DJ#<0i}&w3c@fD0R7G>_5zmOG;13WQE!sR1_P#nG$MF`ELH%bg2bW{h5R&yl8jV^w9KO75`};u0N5f6^_PSb ASO5S3 literal 0 HcmV?d00001 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/36/b3272824712ce55a1a54623fa60b85cb7b164f b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/36/b3272824712ce55a1a54623fa60b85cb7b164f new file mode 100644 index 0000000000000000000000000000000000000000..2e5e2e8c87098c0f3c47e7756bb62b9809b0eacc GIT binary patch literal 54 zcmbQt`q811M literal 0 HcmV?d00001 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/3e/b36aca1a9d0ebcc52e54e190352b206104fe9f b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/3e/b36aca1a9d0ebcc52e54e190352b206104fe9f new file mode 100644 index 0000000000000000000000000000000000000000..8a37170519637f9a2386ca190ab5389e9df80850 GIT binary patch literal 54 zcmbE KYz$_F{5JqHwHBEG literal 0 HcmV?d00001 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/44/3bb80f40ada270ea0d8b9df4ce7f1173a5748a b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/44/3bb80f40ada270ea0d8b9df4ce7f1173a5748a new file mode 100644 index 0000000000000000000000000000000000000000..559d130a36c7c344faa789e0e73491b2a159b5af GIT binary patch literal 158 zcmV;P0Ac@l0i}*X3c@fD06q5=`vJ>tH)$IXQGc?@Zn0n+X(NKKw-kTiapo{g%F{F! zXgD0oVg`zl+fI#>=b)(E877J(Nrr%_=hU_$>Z+$KHWxr?)DgGBQFXxH0+FyK^4Pm5 z4twtmB~8n`~a|l&3S05A3{e9KjJCVzt?Awb);g MUj?Z80=Uvl`ha;%oB#j- literal 0 HcmV?d00001 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/5c/d799fa19eb2e82145ed8211598ec3cb947046e b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/5c/d799fa19eb2e82145ed8211598ec3cb947046e new file mode 100644 index 0000000000000000000000000000000000000000..1f741aefea0532f9f14a16e7a9902839e73c68ff GIT binary patch literal 54 zcmbmKCkiOьYŁKY65cPE%h\`]Hxsq:^5X56?,˙a^ +TإQ>Pr?fHlAB|zKih"6\NܢF-t \ No newline at end of file diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/9b/42fd4bde301c8762baafb8c9b77b56aa63bc48 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/9b/42fd4bde301c8762baafb8c9b77b56aa63bc48 new file mode 100644 index 0000000000000000000000000000000000000000..1977977699ac4288c3aadd97c32702163a7e1fc6 GIT binary patch literal 54 zcmV-60LlM&0V^p=O;s>9XD~D{Ff%bx2y%6F@paY9O<}k@Tl;sSvplnDWzqDg7aNZC Mq!-)=05skZOe6;u7XSbN literal 0 HcmV?d00001 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/9b/63ac63a3e121ef77e8f046c8521d77a7171d35 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/9b/63ac63a3e121ef77e8f046c8521d77a7171d35 new file mode 100644 index 0000000000000000000000000000000000000000..01b10a408cfaf5a2daa60fd6089c5d6c2d5f6917 GIT binary patch literal 75 zcmV-R0JQ&j0ZYosPf{>5WeCa0ELH%bg2bW{h5R&yl8jU!&MZn%2ngch0?P&jDWs>C h6e}d>tvYVzLqW)x)Y_VWlX(NKKSHvH9oH-1WmuVU+ zIN$H;Y6dZM9cjU5(D5-F8e$ap^N={v(z(aG_)#eJQt}ywaK9w?Hw4O-4WfF{> zlrah$YTxLiUY8Zlb6M>P7ke$Y0tfwKo4$D3Mw@Kj+Pq9hAn84eh-26zBQ_uVS*`Y0 M9XD~D{Ff%bx2y%6F@paY9O<_>`m)#`tbcJZpv8dmsD$2)W MT|cP+05lN~W-~4p7ytkO literal 0 HcmV?d00001 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/d2/44ac23bcd16c640ff10e29f70cb9c79c928c56 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/d2/44ac23bcd16c640ff10e29f70cb9c79c928c56 new file mode 100644 index 0000000000000000000000000000000000000000..76c03e7bc7c581ad3de7abbbb3d241efd71c44c5 GIT binary patch literal 54 zcmb7U`ELH%bg2bW{h5R&yl8jV^;?(5)ycC6iATBPjbU=_o TdTL3rLT+kNdTI&)D2o#rP01PA literal 0 HcmV?d00001 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f6/11a4c2dc1894ebbe5e8b558b4055169506048b b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f6/11a4c2dc1894ebbe5e8b558b4055169506048b new file mode 100644 index 0000000000000..cb52e32b2a299 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f6/11a4c2dc1894ebbe5e8b558b4055169506048b @@ -0,0 +1,2 @@ +x[ +0E*f<&IDԝ1m$R܁=Ty zc]F5)]E;/aI/XB7r,یd@UОptR"6.n wϼC%y8JRlvȯZ|K \ No newline at end of file diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f6/211fabb4e7f31f76b64dda1aa8545ff7eb2e78 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f6/211fabb4e7f31f76b64dda1aa8545ff7eb2e78 new file mode 100644 index 0000000000000000000000000000000000000000..0471fb2e3300a20a618c931288e4334ec3029104 GIT binary patch literal 158 zcmV;P0Ac@l0i}*X3c@fD06q5=`vJ=)-ESv;c&=0RgFl#GjW z+(}>>q>)FxE-RepyxJ2k_F8Tk4)VoTzj)e4n{3|Nv`j~EA$Amkj}i7rh|R}-R;&FL M`BlI-Z$D&BykN*k4gdfE literal 0 HcmV?d00001 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f6/3107991a7971d7953be3b96d735cafc576620b b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f6/3107991a7971d7953be3b96d735cafc576620b new file mode 100644 index 0000000000000000000000000000000000000000..78cb1e0e6bfb47f5125c3af002a2e3c7bb73c0be GIT binary patch literal 90 zcmV-g0HyzU0WFJB3V$ulS@w;6YP(BZQG0KzjOUNZ_Q{r~^~ literal 0 HcmV?d00001 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f9/3e3a1a1525fb5b91020da86e44810c87a2d7bc b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/f9/3e3a1a1525fb5b91020da86e44810c87a2d7bc new file mode 100644 index 0000000000000000000000000000000000000000..91fccd447fe1ae44bda5ac217479c40ea5879984 GIT binary patch literal 54 zcmb6wqOX!$ShU>qJqSt5{3LUg_4X^h2qrY{Ja!}fFLd|uyjC> zLV9XRu|jTYQF>|$R4_R|H#f5cq%}7&B~>9Ytt7PwtQ)8rD41W6nn$c!h`9jvpfNGm CX(z(~ literal 0 HcmV?d00001 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/ff/f2d8fe1b36ec3ababaa45266ea4bcfda303858 b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/ff/f2d8fe1b36ec3ababaa45266ea4bcfda303858 new file mode 100644 index 0000000000000000000000000000000000000000..f59c9f97665d1dca03cbc6c67f87c0dc09722f64 GIT binary patch literal 59 zcmV-B0L1@z0ZYosPf{?kU`ELH%bg2bW{h5R&yl8jV^w9KO75`};uE-tWaK#)Rl RNn&NOLViJN9smUN5{nhL88-j` literal 0 HcmV?d00001 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/info/packs b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/info/packs new file mode 100644 index 0000000000000..8b137891791fe --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/objects/info/packs @@ -0,0 +1 @@ + diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/packed-refs b/integrations/gitea-repositories-meta/user2/pr_repo.git/packed-refs new file mode 100644 index 0000000000000..250f187384963 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/packed-refs @@ -0,0 +1 @@ +# pack-refs with: peeled fully-peeled sorted diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/closed_pr b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/closed_pr new file mode 100644 index 0000000000000..c39fc8f7bc584 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/closed_pr @@ -0,0 +1 @@ +0713475aeb24731bf654b5ffb2b0249e9eab6990 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/master b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/master new file mode 100644 index 0000000000000..e86360d99dccb --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/master @@ -0,0 +1 @@ +71ef50ba32849b9b7b4d8c98dd98f5a68134c62f diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/merged_pr b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/merged_pr new file mode 100644 index 0000000000000..f425a406864a5 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/merged_pr @@ -0,0 +1 @@ +2055bdadcecdb500439ac40d578d22bae519bbd5 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/open_pr b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/open_pr new file mode 100644 index 0000000000000..61f6ae0fd2900 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/heads/open_pr @@ -0,0 +1 @@ +c711aebdd140cebd540469c0de87960457a0ab81 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/1/head b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/1/head new file mode 100644 index 0000000000000..61f6ae0fd2900 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/1/head @@ -0,0 +1 @@ +c711aebdd140cebd540469c0de87960457a0ab81 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/2/head b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/2/head new file mode 100644 index 0000000000000..9a8eb338e1bd5 --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/2/head @@ -0,0 +1 @@ +e3dfaeb234e2a4570875ea3be7cedaebf350d703 diff --git a/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/3/head b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/3/head new file mode 100644 index 0000000000000..a16e3f2b2c4df --- /dev/null +++ b/integrations/gitea-repositories-meta/user2/pr_repo.git/refs/pull/3/head @@ -0,0 +1 @@ +f611a4c2dc1894ebbe5e8b558b4055169506048b From 453f2592476444c3ae46e45f0bf876a2247adeee Mon Sep 17 00:00:00 2001 From: AndrewBezold Date: Tue, 30 Jun 2020 11:30:05 -0400 Subject: [PATCH 05/11] Add test PRs to fixtures --- models/fixtures/issue.yml | 36 +++++++++++++++++++++++++++++ models/fixtures/pull_request.yml | 39 ++++++++++++++++++++++++++++++++ models/fixtures/repository.yml | 14 ++++++++++++ 3 files changed, 89 insertions(+) diff --git a/models/fixtures/issue.yml b/models/fixtures/issue.yml index 39a96dc550338..ae15b4976751b 100644 --- a/models/fixtures/issue.yml +++ b/models/fixtures/issue.yml @@ -135,3 +135,39 @@ is_pull: true created_unix: 1579194806 updated_unix: 1579194806 + +- + id: 12 + repo_id: 49 + index: 1 + poster_id: 1 + name: open_pr + content: PR that stays open + is_closed: false + is_pull: true + created_unix: 1593455366 + updated_unix: 1593455423 + +- + id: 13 + repo_id: 49 + index: 2 + poster_id: 1 + name: merged_pr + content: PR that gets merged + is_closed: true + is_pull: true + created_unix: 1593455608 + updated_unix: 1593455740 + +- + id: 14 + repo_id: 49 + index: 3 + poster_id: 1 + name: closed_pr + content: PR that gest closed without merging + is_closed: true + is_pull: true + created_unix: 1593455962 + updated_unix: 1593456141 \ No newline at end of file diff --git a/models/fixtures/pull_request.yml b/models/fixtures/pull_request.yml index b555da83ef762..0d0fe9245759c 100644 --- a/models/fixtures/pull_request.yml +++ b/models/fixtures/pull_request.yml @@ -63,3 +63,42 @@ base_branch: branch1 merge_base: 1234567890abcdef has_merged: false + +- + id: 6 + type: 0 + status: 0 + issue_id: 12 + index: 1 + head_repo_id: 49 + base_repo_id: 49 + head_branch: open_pr + base_branch: master + merge_base: 0a2d4136a3bddf08e911a3ec15084ba40854e0a9 + has_merged: false + +- + id: 7 + type: 0 + status: 3 + issue_id: 13 + index: 2 + head_repo_id: 49 + base_repo_id: 49 + head_branch: merged_pr + base_branch: master + merge_base: 0a2d4136a3bddf08e911a3ec15084ba40854e0a9 + has_merged: true + +- + id: 8 + type: 0 + status: 0 + issue_id: 14 + index: 3 + head_repo_id: 49 + base_repo_id: 49 + head_branch: closed_pr + base_branch: master + merge_base: 0a2d4136a3bddf08e911a3ec15084ba40854e0a9 + has_merged: false \ No newline at end of file diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index 3b86dd0f81f91..522da7aa8c812 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -674,3 +674,17 @@ num_pulls: 1 is_mirror: false status: 0 + +- + id: 49 + owner_id: 2 + owner_name: user2 + lower_name: pr_repo + name: pr_repo + is_private: false + num_stars: 0 + num_forks: 0 + num_issues: 0 + num_pulls: 3 + is_mirror: false + status: 0 From d663e0ecf298898a5b00a30fc62c960151873f89 Mon Sep 17 00:00:00 2001 From: AndrewBezold Date: Wed, 1 Jul 2020 18:50:55 -0400 Subject: [PATCH 06/11] Fix PR units --- models/fixtures/repo_unit.yml | 14 ++++++++++++++ models/fixtures/repository.yml | 1 + 2 files changed, 15 insertions(+) diff --git a/models/fixtures/repo_unit.yml b/models/fixtures/repo_unit.yml index 35b9b92b79525..bb99dea71bb71 100644 --- a/models/fixtures/repo_unit.yml +++ b/models/fixtures/repo_unit.yml @@ -514,3 +514,17 @@ type: 3 config: "{\"IgnoreWhitespaceConflicts\":false,\"AllowMerge\":true,\"AllowRebase\":true,\"AllowRebaseMerge\":true,\"AllowSquash\":true}" created_unix: 946684810 + +- + id: 75 + repo_id: 49 + type: 1 + config: "{}" + created_unix: 946684810 + +- + id: 76 + repo_id: 49 + type: 3 + config: "{}" + created_unix: 946684810 \ No newline at end of file diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index 522da7aa8c812..eab1d62aa72a1 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -686,5 +686,6 @@ num_forks: 0 num_issues: 0 num_pulls: 3 + num_closed_pulls: 2 is_mirror: false status: 0 From d690b0a8305c33ea4b737d0f2d29197e7f843958 Mon Sep 17 00:00:00 2001 From: AndrewBezold Date: Wed, 1 Jul 2020 18:51:10 -0400 Subject: [PATCH 07/11] Fix pull commits if merged --- routers/api/v1/repo/pull.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index c4889b88da9f2..c7523d145c1ab 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -902,13 +902,17 @@ func GetPullRequestCommits(ctx *context.APIContext) { } var prInfo *git.CompareInfo - headGitRepo, err := git.OpenRepository(models.RepoPath(pr.HeadRepo.OwnerName, pr.HeadRepo.Name)) + baseGitRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath()) if err != nil { ctx.ServerError("OpenRepository", err) return } - defer headGitRepo.Close() - prInfo, err = headGitRepo.GetCompareInfo(models.RepoPath(pr.BaseRepo.OwnerName, pr.BaseRepo.Name), pr.BaseBranch, pr.HeadBranch) + defer baseGitRepo.Close() + if pr.HasMerged { + prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.MergeBase, pr.GetGitRefName()) + } else { + prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.BaseBranch, pr.GetGitRefName()) + } if err != nil { ctx.ServerError("GetCompareInfo", err) return From 7abb941c9c7b2b362a57cfb446be6f5f34433a3b Mon Sep 17 00:00:00 2001 From: AndrewBezold Date: Wed, 1 Jul 2020 18:51:21 -0400 Subject: [PATCH 08/11] Add tests for pr commits --- integrations/api_pull_commits_test.go | 75 +++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 integrations/api_pull_commits_test.go diff --git a/integrations/api_pull_commits_test.go b/integrations/api_pull_commits_test.go new file mode 100644 index 0000000000000..db073da734aa3 --- /dev/null +++ b/integrations/api_pull_commits_test.go @@ -0,0 +1,75 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package integrations + +import ( + "net/http" + "testing" + + "code.gitea.io/gitea/models" + api "code.gitea.io/gitea/modules/structs" + "github.com/stretchr/testify/assert" +) + +func TestAPIPullCommits(t *testing.T) { + defer prepareTestEnv(t)() + pullIssue := models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 6}).(*models.PullRequest) + assert.NoError(t, pullIssue.LoadIssue()) + repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue.HeadRepoID}).(*models.Repository) + + // test ListPullReviews + session := loginUser(t, "user2") + req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/commits", repo.OwnerName, repo.Name, pullIssue.Index) + resp := session.MakeRequest(t, req, http.StatusOK) + + var commits []*api.Commit + DecodeJSON(t, resp, &commits) + if !assert.Len(t, commits, 3) { + return + } + assert.Equal(t, "c711aebdd140cebd540469c0de87960457a0ab81", commits[0].SHA) + assert.Equal(t, "f6211fabb4e7f31f76b64dda1aa8545ff7eb2e78", commits[1].SHA) + assert.Equal(t, "443bb80f40ada270ea0d8b9df4ce7f1173a5748a", commits[2].SHA) +} + +func TestAPIMergedPullCommits(t *testing.T) { + defer prepareTestEnv(t)() + pullIssue := models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 7}).(*models.PullRequest) + assert.NoError(t, pullIssue.LoadIssue()) + repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue.HeadRepoID}).(*models.Repository) + + // test ListPullReviews + session := loginUser(t, "user2") + req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/commits", repo.OwnerName, repo.Name, pullIssue.Index) + resp := session.MakeRequest(t, req, http.StatusOK) + + var commits []*api.Commit + DecodeJSON(t, resp, &commits) + if !assert.Len(t, commits, 2) { + return + } + assert.Equal(t, "e3dfaeb234e2a4570875ea3be7cedaebf350d703", commits[0].SHA) + assert.Equal(t, "a20333be2715060c61c8d0268c4f622bde1ae4ac", commits[1].SHA) +} + +func TestAPIClosedPullCommits(t *testing.T) { + defer prepareTestEnv(t)() + pullIssue := models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 8}).(*models.PullRequest) + assert.NoError(t, pullIssue.LoadIssue()) + repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue.HeadRepoID}).(*models.Repository) + + // test ListPullReviews + session := loginUser(t, "user2") + req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/commits", repo.OwnerName, repo.Name, pullIssue.Index) + resp := session.MakeRequest(t, req, http.StatusOK) + + var commits []*api.Commit + DecodeJSON(t, resp, &commits) + if !assert.Len(t, commits, 2) { + return + } + assert.Equal(t, "f611a4c2dc1894ebbe5e8b558b4055169506048b", commits[0].SHA) + assert.Equal(t, "e1adcf142a07305ebf40590a41b1a279486759db", commits[1].SHA) +} From 4a081033d6d2cd0a5e5efcab279ca7eb04517dfb Mon Sep 17 00:00:00 2001 From: AndrewBezold Date: Wed, 1 Jul 2020 19:05:45 -0400 Subject: [PATCH 09/11] Update swagger --- templates/swagger/v1_json.tmpl | 56 ++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index bf011285f81f5..af40edd5d1262 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -6776,6 +6776,62 @@ } } }, + "/repos/{owner}/{repo}/pulls/{index}/commits": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "repository" + ], + "summary": "Get commits for a pull request", + "operationId": "repoGetPullRequestCommits", + "parameters": [ + { + "type": "string", + "description": "owner of the repo", + "name": "owner", + "in": "path", + "required": true + }, + { + "type": "string", + "description": "name of the repo", + "name": "repo", + "in": "path", + "required": true + }, + { + "type": "integer", + "format": "int64", + "description": "index of the pull request to get", + "name": "index", + "in": "path", + "required": true + }, + { + "type": "integer", + "description": "page number of results to return (1-based)", + "name": "page", + "in": "query" + }, + { + "type": "integer", + "description": "page size of results, maximum page size is 50", + "name": "limit", + "in": "query" + } + ], + "responses": { + "200": { + "$ref": "#/responses/CommitList" + }, + "404": { + "$ref": "#/responses/notFound" + } + } + } + }, "/repos/{owner}/{repo}/pulls/{index}/merge": { "get": { "produces": [ From 7e0765e1398d0a38861761e7759cbd57ec968cd8 Mon Sep 17 00:00:00 2001 From: Andrew Bezold Date: Mon, 6 Jul 2020 11:11:12 -0400 Subject: [PATCH 10/11] Remove headRepo load --- routers/api/v1/repo/pull.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index c7523d145c1ab..035f1d91d61f0 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -896,10 +896,6 @@ func GetPullRequestCommits(ctx *context.APIContext) { ctx.InternalServerError(err) return } - if err := pr.LoadHeadRepo(); err != nil { - ctx.InternalServerError(err) - return - } var prInfo *git.CompareInfo baseGitRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath()) From be323a320f3f90ac404213992a5e477ca19d6e2b Mon Sep 17 00:00:00 2001 From: Andrew Bezold Date: Mon, 6 Jul 2020 11:11:25 -0400 Subject: [PATCH 11/11] Update number of repos for user2 --- models/fixtures/user.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index 640fd65bffec1..ebacd2ec0497d 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -30,7 +30,7 @@ is_admin: false avatar: avatar2 avatar_email: user2@example.com - num_repos: 9 + num_repos: 10 num_stars: 2 num_followers: 2 num_following: 1