Skip to content

Commit d331b96

Browse files
authored
Merge branch 'main' into update_vendor
2 parents 4af8dc1 + 8368844 commit d331b96

File tree

12 files changed

+220
-5
lines changed

12 files changed

+220
-5
lines changed

custom/conf/app.example.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ PATH =
10401040
;; Additional Emojis not defined in the utf8 standard
10411041
;; By default we support gitea (:gitea:), to add more copy them to public/img/emoji/emoji_name.png and add it to this config.
10421042
;; Dont mistake it for Reactions.
1043-
;CUSTOM_EMOJIS = gitea
1043+
;CUSTOM_EMOJIS = gitea, codeberg, gitlab, git, github, gogs
10441044
;;
10451045
;; Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used.
10461046
;DEFAULT_SHOW_FULL_NAME = false

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a
181181
- `REACTIONS`: All available reactions users can choose on issues/prs and comments
182182
Values can be emoji alias (:smile:) or a unicode emoji.
183183
For custom reactions, add a tightly cropped square image to public/img/emoji/reaction_name.png
184-
- `CUSTOM_EMOJIS`: **gitea**: Additional Emojis not defined in the utf8 standard.
184+
- `CUSTOM_EMOJIS`: **gitea, codeberg, gitlab, git, github, gogs**: Additional Emojis not defined in the utf8 standard.
185185
By default we support gitea (:gitea:), to add more copy them to public/img/emoji/emoji_name.png and
186186
add it to this config.
187187
- `DEFAULT_SHOW_FULL_NAME`: **false**: Whether the full name of the users should be shown where possible. If the full name isn't set, the username will be used.
@@ -392,7 +392,7 @@ relation to port exhaustion.
392392
- `MAX_ATTEMPTS`: **10**: Maximum number of attempts to create the wrapped queue
393393
- `TIMEOUT`: **GRACEFUL_HAMMER_TIME + 30s**: Timeout the creation of the wrapped queue if it takes longer than this to create.
394394
- Queues by default come with a dynamically scaling worker pool. The following settings configure this:
395-
- `WORKERS`: **0** (v1.14 and before: **1**): Number of initial workers for the queue.
395+
- `WORKERS`: **0** (v1.14 and before: **1**): Number of initial workers for the queue.
396396
- `MAX_WORKERS`: **10**: Maximum number of worker go-routines for the queue.
397397
- `BLOCK_TIMEOUT`: **1s**: If the queue blocks for this time, boost the number of workers - the `BLOCK_TIMEOUT` will then be doubled before boosting again whilst the boost is ongoing.
398398
- `BOOST_TIMEOUT`: **5m**: Boost workers will timeout after this long.

integrations/api_pull_commits_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright 2021 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package integrations
6+
7+
import (
8+
"net/http"
9+
"testing"
10+
11+
"code.gitea.io/gitea/models"
12+
api "code.gitea.io/gitea/modules/structs"
13+
"github.com/stretchr/testify/assert"
14+
)
15+
16+
func TestAPIPullCommits(t *testing.T) {
17+
defer prepareTestEnv(t)()
18+
pullIssue := models.AssertExistsAndLoadBean(t, &models.PullRequest{ID: 2}).(*models.PullRequest)
19+
assert.NoError(t, pullIssue.LoadIssue())
20+
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: pullIssue.HeadRepoID}).(*models.Repository)
21+
22+
session := loginUser(t, "user2")
23+
req := NewRequestf(t, http.MethodGet, "/api/v1/repos/%s/%s/pulls/%d/commits", repo.OwnerName, repo.Name, pullIssue.Index)
24+
resp := session.MakeRequest(t, req, http.StatusOK)
25+
26+
var commits []*api.Commit
27+
DecodeJSON(t, resp, &commits)
28+
29+
if !assert.Len(t, commits, 2) {
30+
return
31+
}
32+
33+
assert.Equal(t, "5f22f7d0d95d614d25a5b68592adb345a4b5c7fd", commits[0].SHA)
34+
assert.Equal(t, "4a357436d925b5c974181ff12a994538ddc5a269", commits[1].SHA)
35+
}
36+
37+
// TODO add tests for already merged PR and closed PR

modules/setting/setting.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ var (
258258
DefaultTheme: `gitea`,
259259
Themes: []string{`gitea`, `arc-green`},
260260
Reactions: []string{`+1`, `-1`, `laugh`, `hooray`, `confused`, `heart`, `rocket`, `eyes`},
261-
CustomEmojis: []string{`gitea`},
262-
CustomEmojisMap: map[string]string{"gitea": ":gitea:"},
261+
CustomEmojis: []string{`git`, `gitea`, `codeberg`, `gitlab`, `github`, `gogs`},
262+
CustomEmojisMap: map[string]string{"git": ":git:", "gitea": ":gitea:", "codeberg": ":codeberg:", "gitlab": ":gitlab:", "github": ":github:", "gogs": ":gogs:"},
263263
Notification: struct {
264264
MinTimeout time.Duration
265265
TimeoutStep time.Duration

public/img/emoji/codeberg.png

8.12 KB
Loading

public/img/emoji/git.png

4.89 KB
Loading

public/img/emoji/github.png

13.8 KB
Loading

public/img/emoji/gitlab.png

6.71 KB
Loading

public/img/emoji/gogs.png

11.5 KB
Loading

routers/api/v1/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,7 @@ func Routes() *web.Route {
905905
m.Get(".diff", repo.DownloadPullDiff)
906906
m.Get(".patch", repo.DownloadPullPatch)
907907
m.Post("/update", reqToken(), repo.UpdatePullRequest)
908+
m.Get("/commits", repo.GetPullRequestCommits)
908909
m.Combo("/merge").Get(repo.IsPullRequestMerged).
909910
Post(reqToken(), mustNotBeArchived, bind(forms.MergePullRequestForm{}), repo.MergePullRequest)
910911
m.Group("/reviews", func() {

routers/api/v1/repo/pull.go

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ package repo
66

77
import (
88
"fmt"
9+
"math"
910
"net/http"
11+
"strconv"
1012
"strings"
1113
"time"
1214

@@ -1101,3 +1103,122 @@ func UpdatePullRequest(ctx *context.APIContext) {
11011103

11021104
ctx.Status(http.StatusOK)
11031105
}
1106+
1107+
// GetPullRequestCommits gets all commits associated with a given PR
1108+
func GetPullRequestCommits(ctx *context.APIContext) {
1109+
// swagger:operation GET /repos/{owner}/{repo}/pulls/{index}/commits repository repoGetPullRequestCommits
1110+
// ---
1111+
// summary: Get commits for a pull request
1112+
// produces:
1113+
// - application/json
1114+
// parameters:
1115+
// - name: owner
1116+
// in: path
1117+
// description: owner of the repo
1118+
// type: string
1119+
// required: true
1120+
// - name: repo
1121+
// in: path
1122+
// description: name of the repo
1123+
// type: string
1124+
// required: true
1125+
// - name: index
1126+
// in: path
1127+
// description: index of the pull request to get
1128+
// type: integer
1129+
// format: int64
1130+
// required: true
1131+
// - name: page
1132+
// in: query
1133+
// description: page number of results to return (1-based)
1134+
// type: integer
1135+
// - name: limit
1136+
// in: query
1137+
// description: page size of results
1138+
// type: integer
1139+
// responses:
1140+
// "200":
1141+
// "$ref": "#/responses/CommitList"
1142+
// "404":
1143+
// "$ref": "#/responses/notFound"
1144+
1145+
pr, err := models.GetPullRequestByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
1146+
if err != nil {
1147+
if models.IsErrPullRequestNotExist(err) {
1148+
ctx.NotFound()
1149+
} else {
1150+
ctx.Error(http.StatusInternalServerError, "GetPullRequestByIndex", err)
1151+
}
1152+
return
1153+
}
1154+
1155+
if err := pr.LoadBaseRepo(); err != nil {
1156+
ctx.InternalServerError(err)
1157+
return
1158+
}
1159+
1160+
var prInfo *git.CompareInfo
1161+
baseGitRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath())
1162+
if err != nil {
1163+
ctx.ServerError("OpenRepository", err)
1164+
return
1165+
}
1166+
defer baseGitRepo.Close()
1167+
if pr.HasMerged {
1168+
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.MergeBase, pr.GetGitRefName())
1169+
} else {
1170+
prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.BaseBranch, pr.GetGitRefName())
1171+
}
1172+
if err != nil {
1173+
ctx.ServerError("GetCompareInfo", err)
1174+
return
1175+
}
1176+
commits := prInfo.Commits
1177+
1178+
listOptions := utils.GetListOptions(ctx)
1179+
1180+
totalNumberOfCommits := commits.Len()
1181+
totalNumberOfPages := int(math.Ceil(float64(totalNumberOfCommits) / float64(listOptions.PageSize)))
1182+
1183+
userCache := make(map[string]*models.User)
1184+
1185+
start, end := listOptions.GetStartEnd()
1186+
1187+
if end > totalNumberOfCommits {
1188+
end = totalNumberOfCommits
1189+
}
1190+
1191+
apiCommits := make([]*api.Commit, end-start)
1192+
1193+
i := 0
1194+
addedCommitsCount := 0
1195+
for commitPointer := commits.Front(); commitPointer != nil; commitPointer = commitPointer.Next() {
1196+
if i < start {
1197+
i++
1198+
continue
1199+
}
1200+
if i >= end {
1201+
break
1202+
}
1203+
1204+
commit := commitPointer.Value.(*git.Commit)
1205+
1206+
// Create json struct
1207+
apiCommits[addedCommitsCount], err = convert.ToCommit(ctx.Repo.Repository, commit, userCache)
1208+
addedCommitsCount++
1209+
if err != nil {
1210+
ctx.ServerError("toCommit", err)
1211+
return
1212+
}
1213+
i++
1214+
}
1215+
1216+
ctx.SetLinkHeader(int(totalNumberOfCommits), listOptions.PageSize)
1217+
1218+
ctx.Header().Set("X-Page", strconv.Itoa(listOptions.Page))
1219+
ctx.Header().Set("X-PerPage", strconv.Itoa(listOptions.PageSize))
1220+
ctx.Header().Set("X-Total-Count", fmt.Sprintf("%d", totalNumberOfCommits))
1221+
ctx.Header().Set("X-PageCount", strconv.Itoa(totalNumberOfPages))
1222+
ctx.Header().Set("X-HasMore", strconv.FormatBool(listOptions.Page < totalNumberOfPages))
1223+
ctx.JSON(http.StatusOK, &apiCommits)
1224+
}

templates/swagger/v1_json.tmpl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7333,6 +7333,62 @@
73337333
}
73347334
}
73357335
},
7336+
"/repos/{owner}/{repo}/pulls/{index}/commits": {
7337+
"get": {
7338+
"produces": [
7339+
"application/json"
7340+
],
7341+
"tags": [
7342+
"repository"
7343+
],
7344+
"summary": "Get commits for a pull request",
7345+
"operationId": "repoGetPullRequestCommits",
7346+
"parameters": [
7347+
{
7348+
"type": "string",
7349+
"description": "owner of the repo",
7350+
"name": "owner",
7351+
"in": "path",
7352+
"required": true
7353+
},
7354+
{
7355+
"type": "string",
7356+
"description": "name of the repo",
7357+
"name": "repo",
7358+
"in": "path",
7359+
"required": true
7360+
},
7361+
{
7362+
"type": "integer",
7363+
"format": "int64",
7364+
"description": "index of the pull request to get",
7365+
"name": "index",
7366+
"in": "path",
7367+
"required": true
7368+
},
7369+
{
7370+
"type": "integer",
7371+
"description": "page number of results to return (1-based)",
7372+
"name": "page",
7373+
"in": "query"
7374+
},
7375+
{
7376+
"type": "integer",
7377+
"description": "page size of results",
7378+
"name": "limit",
7379+
"in": "query"
7380+
}
7381+
],
7382+
"responses": {
7383+
"200": {
7384+
"$ref": "#/responses/CommitList"
7385+
},
7386+
"404": {
7387+
"$ref": "#/responses/notFound"
7388+
}
7389+
}
7390+
}
7391+
},
73367392
"/repos/{owner}/{repo}/pulls/{index}/merge": {
73377393
"get": {
73387394
"produces": [

0 commit comments

Comments
 (0)