4
4
package integration
5
5
6
6
import (
7
+ "encoding/base64"
7
8
"fmt"
8
9
"net/http"
9
10
"net/url"
@@ -28,6 +29,7 @@ import (
28
29
api "code.gitea.io/gitea/modules/structs"
29
30
"code.gitea.io/gitea/modules/test"
30
31
"code.gitea.io/gitea/modules/timeutil"
32
+ "code.gitea.io/gitea/modules/util"
31
33
issue_service "code.gitea.io/gitea/services/issue"
32
34
pull_service "code.gitea.io/gitea/services/pull"
33
35
release_service "code.gitea.io/gitea/services/release"
@@ -1368,3 +1370,81 @@ jobs:
1368
1370
assert .Equal (t , "true" , dispatchPayload .Inputs ["myinput3" ])
1369
1371
})
1370
1372
}
1373
+
1374
+ func TestClosePullRequestWithPath (t * testing.T ) {
1375
+ onGiteaRun (t , func (t * testing.T , u * url.URL ) {
1376
+ // user2 is the owner of the base repo
1377
+ user2 := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 2 })
1378
+ user2Token := getTokenForLoggedInUser (t , loginUser (t , user2 .Name ), auth_model .AccessTokenScopeWriteRepository , auth_model .AccessTokenScopeWriteUser )
1379
+ // user4 is the owner of the fork repo
1380
+ user4 := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 4 })
1381
+ user4Token := getTokenForLoggedInUser (t , loginUser (t , user4 .Name ), auth_model .AccessTokenScopeWriteRepository , auth_model .AccessTokenScopeWriteUser )
1382
+
1383
+ // create the base repo
1384
+ apiBaseRepo := createActionsTestRepo (t , user2Token , "close-pull-request-with-path" , false )
1385
+ baseRepo := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {ID : apiBaseRepo .ID })
1386
+ user2APICtx := NewAPITestContext (t , baseRepo .OwnerName , baseRepo .Name , auth_model .AccessTokenScopeWriteRepository )
1387
+
1388
+ // init the workflow
1389
+ wfTreePath := ".gitea/workflows/pull.yml"
1390
+ wfFileContent := `name: Pull Request
1391
+ on:
1392
+ pull_request:
1393
+ types:
1394
+ - closed
1395
+ paths:
1396
+ - 'app/**'
1397
+ jobs:
1398
+ echo:
1399
+ runs-on: ubuntu-latest
1400
+ steps:
1401
+ - run: echo 'Hello World'
1402
+ `
1403
+ opts1 := getWorkflowCreateFileOptions (user2 , baseRepo .DefaultBranch , "create " + wfTreePath , wfFileContent )
1404
+ createWorkflowFile (t , user2Token , baseRepo .OwnerName , baseRepo .Name , wfTreePath , opts1 )
1405
+
1406
+ // user4 forks the repo
1407
+ req := NewRequestWithJSON (t , "POST" , fmt .Sprintf ("/api/v1/repos/%s/%s/forks" , baseRepo .OwnerName , baseRepo .Name ),
1408
+ & api.CreateForkOption {
1409
+ Name : util .ToPointer ("close-pull-request-with-path-fork" ),
1410
+ }).AddTokenAuth (user4Token )
1411
+ resp := MakeRequest (t , req , http .StatusAccepted )
1412
+ var apiForkRepo api.Repository
1413
+ DecodeJSON (t , resp , & apiForkRepo )
1414
+ forkRepo := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {ID : apiForkRepo .ID })
1415
+ user4APICtx := NewAPITestContext (t , user4 .Name , forkRepo .Name , auth_model .AccessTokenScopeWriteRepository )
1416
+
1417
+ // user4 creates a pull request to add file "app/main.go"
1418
+ doAPICreateFile (user4APICtx , "app/main.go" , & api.CreateFileOptions {
1419
+ FileOptions : api.FileOptions {
1420
+ NewBranchName : "user4/add-main" ,
1421
+ Message : "create main.go" ,
1422
+ Author : api.Identity {
1423
+ Name : user4 .Name ,
1424
+ Email : user4 .Email ,
1425
+ },
1426
+ Committer : api.Identity {
1427
+ Name : user4 .Name ,
1428
+ Email : user4 .Email ,
1429
+ },
1430
+ Dates : api.CommitDateOptions {
1431
+ Author : time .Now (),
1432
+ Committer : time .Now (),
1433
+ },
1434
+ },
1435
+ ContentBase64 : base64 .StdEncoding .EncodeToString ([]byte ("// main.go" )),
1436
+ })(t )
1437
+ apiPull , err := doAPICreatePullRequest (user4APICtx , baseRepo .OwnerName , baseRepo .Name , baseRepo .DefaultBranch , user4 .Name + ":user4/add-main" )(t )
1438
+ assert .NoError (t , err )
1439
+
1440
+ doAPIMergePullRequest (user2APICtx , baseRepo .OwnerName , baseRepo .Name , apiPull .Index )(t )
1441
+
1442
+ pullRequest := unittest .AssertExistsAndLoadBean (t , & issues_model.PullRequest {ID : apiPull .ID })
1443
+
1444
+ // load and compare ActionRun
1445
+ assert .Equal (t , 1 , unittest .GetCount (t , & actions_model.ActionRun {RepoID : baseRepo .ID }))
1446
+ actionRun := unittest .AssertExistsAndLoadBean (t , & actions_model.ActionRun {RepoID : baseRepo .ID })
1447
+ assert .Equal (t , actions_module .GithubEventPullRequest , actionRun .TriggerEvent )
1448
+ assert .Equal (t , pullRequest .MergedCommitID , actionRun .CommitSHA )
1449
+ })
1450
+ }
0 commit comments