@@ -18,6 +18,7 @@ public void SetUp()
18
18
this . environment = sp . GetRequiredService < IEnvironment > ( ) ;
19
19
this . buildServer = sp . GetRequiredService < GitHubActions > ( ) ;
20
20
this . environment . SetEnvironmentVariable ( GitHubActions . EnvironmentVariableName , "true" ) ;
21
+ this . environment . SetEnvironmentVariable ( "GITHUB_REF_TYPE" , "branch" ) ;
21
22
22
23
this . githubSetEnvironmentTempFilePath = Path . GetTempFileName ( ) ;
23
24
this . environment . SetEnvironmentVariable ( GitHubActions . GitHubSetEnvTempFileEnvironmentVariableName , this . githubSetEnvironmentTempFilePath ) ;
@@ -75,26 +76,30 @@ public void GetCurrentBranchShouldHandleBranches()
75
76
public void GetCurrentBranchShouldHandleTags ( )
76
77
{
77
78
// Arrange
79
+ this . environment . SetEnvironmentVariable ( "GITHUB_REF_TYPE" , "tag" ) ;
78
80
this . environment . SetEnvironmentVariable ( "GITHUB_REF" , "refs/tags/1.0.0" ) ;
79
81
80
82
// Act
81
83
var result = this . buildServer . GetCurrentBranch ( false ) ;
82
84
83
85
// Assert
84
- result . ShouldBe ( "refs/tags/1.0.0" ) ;
86
+ result . ShouldBeNull ( ) ;
85
87
}
86
88
87
89
[ Test ]
88
90
public void GetCurrentBranchShouldHandlePullRequests ( )
89
91
{
90
92
// Arrange
93
+ this . environment . SetEnvironmentVariable ( "GITHUB_EVENT_NAME" , "pull_request" ) ;
94
+ this . environment . SetEnvironmentVariable ( "GITHUB_HEAD_REF" , "some-branch" ) ;
95
+ this . environment . SetEnvironmentVariable ( "GITHUB_BASE_REF" , MainBranch ) ;
91
96
this . environment . SetEnvironmentVariable ( "GITHUB_REF" , "refs/pull/1/merge" ) ;
92
97
93
98
// Act
94
99
var result = this . buildServer . GetCurrentBranch ( false ) ;
95
100
96
101
// Assert
97
- result . ShouldBe ( "refs/pull/1/merge " ) ;
102
+ result . ShouldBe ( "some-branch " ) ;
98
103
}
99
104
100
105
[ Test ]
0 commit comments