@@ -22,13 +22,9 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
__setModuleDefault ( result , mod ) ;
23
23
return result ;
24
24
} ;
25
- var __importDefault = ( this && this . __importDefault ) || function ( mod ) {
26
- return ( mod && mod . __esModule ) ? mod : { "default" : mod } ;
27
- } ;
28
25
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
29
26
exports . handlePROpened = void 0 ;
30
27
const github = __importStar ( require ( "@actions/github" ) ) ;
31
- const axios_1 = __importDefault ( require ( "axios" ) ) ;
32
28
async function handlePROpened ( slackToken , slackChannel , githubToken , initialMessageTemplate , commitListMessageTemplate , githubToSlackMap ) {
33
29
const pr = github . context . payload . pull_request ;
34
30
if ( ! pr ) {
@@ -46,58 +42,68 @@ async function handlePROpened(slackToken, slackChannel, githubToken, initialMess
46
42
. replace ( '${branchName}' , branchName )
47
43
. replace ( '${targetBranch}' , targetBranch )
48
44
. replace ( / \\ n / g, '\n' ) ;
49
- const initialMessageResponse = await axios_1 . default . post ( 'https://slack.com/api/chat.postMessage' , {
50
- channel : slackChannel ,
51
- text : initialMessage
52
- } , {
45
+ const initialMessageResponse = await fetch ( 'https://slack.com/api/chat.postMessage' , {
46
+ method : 'POST' ,
53
47
headers : {
54
- 'Authorization' : `Bearer ${ slackToken } ` ,
55
- 'Content-Type' : 'application/json'
56
- }
48
+ Authorization : `Bearer ${ slackToken } ` ,
49
+ 'Content-Type' : 'application/json' ,
50
+ } ,
51
+ body : JSON . stringify ( {
52
+ channel : slackChannel ,
53
+ text : initialMessage ,
54
+ } ) ,
57
55
} ) ;
58
- if ( ! initialMessageResponse . data . ok ) {
56
+ const initialMessageData = await initialMessageResponse . json ( ) ;
57
+ if ( ! initialMessageData . ok ) {
59
58
throw new Error ( 'Failed to send initial Slack message' ) ;
60
59
}
61
- const messageTs = initialMessageResponse . data . ts ;
60
+ const messageTs = initialMessageData . ts ;
62
61
const newPrBody = `Slack message_ts: ${ messageTs } \n\n${ prBody } ` ;
63
62
const octokit = github . getOctokit ( githubToken ) ;
64
63
await octokit . rest . pulls . update ( {
65
64
...github . context . repo ,
66
65
pull_number : prNumber ,
67
- body : newPrBody
66
+ body : newPrBody ,
68
67
} ) ;
69
68
const commitsUrl = pr . commits_url ;
70
- const commitsResponse = await axios_1 . default . get ( commitsUrl , {
69
+ const commitsResponse = await fetch ( commitsUrl , {
71
70
headers : {
72
- ' Authorization' : `token ${ githubToken } `
73
- }
71
+ Authorization : `token ${ githubToken } ` ,
72
+ } ,
74
73
} ) ;
74
+ const commitsData = await commitsResponse . json ( ) ;
75
75
const repoUrl = `https://github.com/${ github . context . repo . owner } /${ github . context . repo . repo } ` ;
76
- const commitMessages = commitsResponse . data . map ( ( commit ) => {
77
- const commitMessage = commit . commit . message ;
76
+ const commitMessages = commitsData
77
+ . map ( ( commit ) => {
78
+ const commitMessage = commit . commit . message . split ( '\n' ) [ 0 ] ; // Extract only the first line
78
79
const commitSha = commit . sha ;
79
80
const commitUrl = `${ repoUrl } /commit/${ commitSha } ` ;
80
81
const githubUser = commit . author ?. login || commit . commit . author . name ;
81
- const slackUserId = githubToSlackMap ? githubToSlackMap [ githubUser ] : githubUser ;
82
+ const slackUserId = githubToSlackMap
83
+ ? githubToSlackMap [ githubUser ]
84
+ : null ;
82
85
const userDisplay = slackUserId ? `<@${ slackUserId } >` : `@${ githubUser } ` ;
83
86
return `- <${ commitUrl } |${ commitMessage } > by ${ userDisplay } ` ;
84
- } ) . join ( '\n' ) ;
87
+ } )
88
+ . join ( '\n' ) ;
85
89
const changelogUrl = `${ repoUrl } /compare/${ targetBranch } ...${ branchName } ` ;
86
90
const commitListMessage = commitListMessageTemplate
87
91
. replace ( '${commitListMessage}' , commitMessages )
88
92
. replace ( '${changelogUrl}' , changelogUrl )
89
93
. replace ( '${branchName}' , branchName )
90
94
. replace ( '${targetBranch}' , targetBranch )
91
95
. replace ( / \\ n / g, '\n' ) ; // Replace escaped newline characters with actual newline characters
92
- await axios_1 . default . post ( 'https://slack.com/api/chat.postMessage' , {
93
- channel : slackChannel ,
94
- text : commitListMessage ,
95
- thread_ts : messageTs
96
- } , {
96
+ await fetch ( 'https://slack.com/api/chat.postMessage' , {
97
+ method : 'POST' ,
97
98
headers : {
98
- 'Authorization' : `Bearer ${ slackToken } ` ,
99
- 'Content-Type' : 'application/json'
100
- }
99
+ Authorization : `Bearer ${ slackToken } ` ,
100
+ 'Content-Type' : 'application/json' ,
101
+ } ,
102
+ body : JSON . stringify ( {
103
+ channel : slackChannel ,
104
+ text : commitListMessage ,
105
+ thread_ts : messageTs ,
106
+ } ) ,
101
107
} ) ;
102
108
}
103
109
exports . handlePROpened = handlePROpened ;
0 commit comments