@@ -30,7 +30,6 @@ import static pl.allegro.tech.build.axion.release.domain.scm.ScmPropertiesBuilde
30
30
31
31
class GitRepositoryTest extends Specification {
32
32
33
- public static final String MASTER_BRANCH = " master"
34
33
File repositoryDir
35
34
36
35
File remoteRepositoryDir
@@ -43,6 +42,8 @@ class GitRepositoryTest extends Specification {
43
42
44
43
GitRepository repository
45
44
45
+ String defaultBranch;
46
+
46
47
void setup () {
47
48
remoteRepositoryDir = File . createTempDir(' axion-release' , ' tmp' )
48
49
Map remoteRepositories = GitProjectBuilder . gitProject(remoteRepositoryDir). withInitialCommit(). build()
@@ -54,6 +55,9 @@ class GitRepositoryTest extends Specification {
54
55
55
56
rawRepository = repositories[Grgit ]
56
57
repository = repositories[GitRepository ]
58
+
59
+ assert rawRepository. branch. current(). name == remoteRawRepository. branch. current(). name
60
+ defaultBranch = rawRepository. branch. current(). name
57
61
}
58
62
59
63
def " should throw unavailable exception when initializing in unexisitng repository" () {
@@ -592,7 +596,7 @@ class GitRepositoryTest extends Specification {
592
596
git. checkout(). setName(secondBranchName). call()
593
597
commitFile(' second/aa' , ' foo' )
594
598
commitFile(' b/ba' , ' bar' )
595
- git. checkout(). setName(MASTER_BRANCH ). call()
599
+ git. checkout(). setName(defaultBranch ). call()
596
600
git. merge(). include(git. repository. resolve(secondBranchName)). setCommit(true ). setMessage(" unintresting" ). setFastForward(MergeCommand.FastForwardMode . NO_FF ). call()
597
601
598
602
commitFile(' after/aa' , ' after' )
@@ -631,7 +635,6 @@ class GitRepositoryTest extends Specification {
631
635
632
636
@WithEnvironment ([
633
637
' GITHUB_ACTIONS=true' ,
634
- ' GITHUB_EVENT_NAME=pull_request' ,
635
638
' GITHUB_HEAD_REF=pr-source-branch'
636
639
])
637
640
def " should get branch name on Github Actions if pull_request triggered the workflow" () {
@@ -644,15 +647,14 @@ class GitRepositoryTest extends Specification {
644
647
645
648
@WithEnvironment ([
646
649
' GITHUB_ACTIONS=true' ,
647
- ' GITHUB_EVENT_NAME=pull_request_target' ,
648
- ' GITHUB_HEAD_REF=pr-source-branch'
650
+ ' GITHUB_HEAD_REF='
649
651
])
650
- def " should get branch name on Github Actions if pull_request_target triggered the workflow " () {
652
+ def " should ignore GITHUB_HEAD_REF variable if it has empty value " () {
651
653
when :
652
654
ScmPosition position = repository. currentPosition()
653
655
654
656
then :
655
- position. branch == ' pr-source-branch '
657
+ position. branch == defaultBranch
656
658
}
657
659
658
660
private void commitFile (String subDir , String fileName ) {
0 commit comments