@@ -5,6 +5,7 @@ import DEFAULT_RELEASE_TYPES from '@semantic-release/commit-analyzer/lib/default
5
5
import { compareCommits , listTags } from './github' ;
6
6
import { defaultChangelogRules } from './defaults' ;
7
7
import { Await } from './ts' ;
8
+ import { context } from "@actions/github" ;
8
9
9
10
type Tags = Await < ReturnType < typeof listTags > > ;
10
11
@@ -30,19 +31,53 @@ export async function getValidTags(
30
31
31
32
return validTags ;
32
33
}
34
+ interface FinalCommit {
35
+ sha : string | null ;
36
+ commit : {
37
+ message : string ;
38
+ }
39
+ }
40
+
33
41
34
42
export async function getCommits (
35
- baseRef : string ,
36
- headRef : string
43
+ baseRef : string ,
44
+ headRef : string
37
45
) : Promise < { message : string ; hash : string | null } [ ] > {
38
- const commits = await compareCommits ( baseRef , headRef ) ;
39
-
40
- return commits
41
- . filter ( ( commit ) => ! ! commit . commit . message )
42
- . map ( ( commit ) => ( {
43
- message : commit . commit . message ,
44
- hash : commit . sha ,
45
- } ) ) ;
46
+ let commits : Array < FinalCommit > ;
47
+ commits = await compareCommits ( baseRef , headRef ) ;
48
+ core . info ( "We found " + commits . length + " commits using classic compare!" )
49
+ if ( commits . length < 1 ) {
50
+ core . info ( "We did not find enough commits, attempting to scan closed PR method." )
51
+ commits = getClosedPRCommits ( ) ;
52
+ }
53
+ if ( commits . length == 0 ) {
54
+ return [ ]
55
+ }
56
+
57
+ return commits
58
+ . filter ( ( commit : FinalCommit ) => ! ! commit . commit . message )
59
+ . map ( ( commit : FinalCommit ) => ( {
60
+ message : commit . commit . message ,
61
+ hash : commit . sha ,
62
+ } ) )
63
+ }
64
+
65
+ function getClosedPRCommits ( ) {
66
+ let commits = Array < FinalCommit > ( ) ;
67
+ if ( ! ( 'pull_request' in context . payload ) ) {
68
+ core . debug ( "We are in a closed PR context continuing." ) ;
69
+ core . debug ( JSON . stringify ( context . payload . commits ) )
70
+ let pr_commit_count = context . payload . commits . length
71
+ core . info ( "We found " + pr_commit_count + " commits from the Closed PR method." )
72
+ commits = context . payload . commits
73
+ . filter ( ( commit : FinalCommit ) => ! ! commit . commit . message )
74
+ . filter ( ( commit : FinalCommit ) => ( {
75
+ message : commit . commit . message ,
76
+ hash : commit . sha ,
77
+ } ) ) ;
78
+ core . debug ( "After processing we are going to present " + commits . length + " commits!" )
79
+ }
80
+ return commits ;
46
81
}
47
82
48
83
export function getBranchFromRef ( ref : string ) {
0 commit comments