@@ -45,36 +45,56 @@ function bearer() {
45
45
}
46
46
47
47
async function getGithubRelease ( ) {
48
- const tag = process . env . TAG
48
+ const commitId = process . env . COMMIT_ID
49
49
50
- if ( ! tag ) {
50
+ if ( ! commitId ) {
51
51
return getLatestGithubRelease ( )
52
52
}
53
53
54
- return getGithubReleaseByTag ( tag )
54
+ console . info ( 'Using commit id' , commitId )
55
+
56
+ return getGithubReleaseByCommitId ( commitId )
57
+ }
58
+
59
+ async function listTags ( ) {
60
+ const url = `https://api.github.com/repos/${ config . owner } /${ config . repo } /tags`
61
+
62
+ console . debug ( 'fetchTags url' , url )
63
+
64
+ return await doGithubGetRequest ( url )
65
+ }
66
+
67
+ async function getGithubReleaseByCommitId ( commitId ) {
68
+ const tag = await listTags ( ) . then ( ( response ) => findTagByCommitId ( response , commitId ) )
69
+
70
+ if ( ! tag ) {
71
+ throw new Error ( `Tag for commit ${ commitId } not found` )
72
+ }
73
+
74
+ return await getGithubReleaseByTag ( tag . name )
55
75
}
56
76
57
77
async function getGithubReleaseByTag ( tag ) {
58
78
const url = `https://api.github.com/repos/${ config . owner } /${ config . repo } /releases/tags/${ tag } `
59
79
60
- console . debug ( 'url' , url )
80
+ console . debug ( 'getGithubReleaseByTag url' , url )
61
81
62
- const response = await fetch ( url , {
63
- headers : config . token
64
- ? {
65
- Authorization : bearer ( config . token ) ,
66
- }
67
- : undefined ,
68
- } )
82
+ return await doGithubGetRequest ( url )
83
+ }
69
84
70
- return response . json ( )
85
+ function findTagByCommitId ( tags , commitId ) {
86
+ return tags . find ( ( tag ) => tag ?. commit ?. sha === commitId )
71
87
}
72
88
73
89
async function getLatestGithubRelease ( ) {
74
90
const url = `https://api.github.com/repos/${ config . owner } /${ config . repo } /releases/latest`
75
91
76
- console . info ( 'url' , url )
92
+ console . info ( 'getLatestGithubRelease url' , url )
93
+
94
+ return await doGithubGetRequest ( url )
95
+ }
77
96
97
+ async function doGithubGetRequest ( url ) {
78
98
const response = await fetch ( url , {
79
99
headers : config . token
80
100
? {
0 commit comments