@@ -26,21 +26,19 @@ async function exec(req: any, action: Action): Promise<Action> {
26
26
if ( refUpdates . length !== 1 ) {
27
27
step . log ( 'Invalid number of branch updates.' ) ;
28
28
step . log ( `Expected 1, but got ${ refUpdates . length } ` ) ;
29
- step . setError ( 'Your push has been blocked. Please make sure you are pushing to a single branch.' ) ;
29
+ step . setError (
30
+ 'Your push has been blocked. Please make sure you are pushing to a single branch.' ,
31
+ ) ;
30
32
action . addStep ( step ) ;
31
33
return action ;
32
34
}
33
35
34
- const cleanedUpdates = refUpdates . map ( ( line ) => {
35
- const [ oldOid , newOid , refWithNull ] = line . split ( ' ' ) ;
36
- const ref = refWithNull . replace ( / \0 .* / , '' ) . trim ( ) ;
37
- return { oldOid, newOid, ref } ;
38
- } ) ;
36
+ const parts = refUpdates [ 0 ] . split ( ' ' ) ;
37
+ const [ oldOid , newOid , rawRef ] = parts ;
39
38
40
- action . updatedRefs = cleanedUpdates ;
39
+ const branch = rawRef . replace ( / \0 . * / , '' ) . trim ( ) ;
41
40
42
- const { oldOid, newOid, ref } = cleanedUpdates [ 0 ] ;
43
- action . branch = ref ;
41
+ action . branch = branch ;
44
42
action . setCommit ( oldOid , newOid ) ;
45
43
46
44
// Check if the offset is valid and if there's data after it
@@ -66,13 +64,13 @@ async function exec(req: any, action: Action): Promise<Action> {
66
64
67
65
action . commitData = getCommitData ( contents as any ) ;
68
66
if ( action . commitData . length === 0 ) {
69
- step . log ( 'No commit data found when parsing push.' )
67
+ step . log ( 'No commit data found when parsing push.' ) ;
70
68
} else {
71
69
if ( action . commitFrom === '0000000000000000000000000000000000000000' ) {
72
70
action . commitFrom = action . commitData [ action . commitData . length - 1 ] . parent ;
73
71
}
74
72
const user = action . commitData [ action . commitData . length - 1 ] . committer ;
75
- action . user = user ;
73
+ action . user = user ;
76
74
}
77
75
78
76
step . content = {
@@ -86,20 +84,24 @@ async function exec(req: any, action: Action): Promise<Action> {
86
84
action . addStep ( step ) ;
87
85
}
88
86
return action ;
89
- } ;
87
+ }
90
88
91
89
/**
92
90
* Parses the name, email, and timestamp from an author or committer line.
93
- *
91
+ *
94
92
* Timestamp including timezone offset is required.
95
93
* @param {string } line - The line to parse.
96
94
* @return {Object } An object containing the name, email, and timestamp.
97
95
*/
98
- const parsePersonLine = ( line : string ) : { name : string ; email : string ; timestamp : string } | null => {
96
+ const parsePersonLine = (
97
+ line : string ,
98
+ ) : { name : string ; email : string ; timestamp : string } | null => {
99
99
const personRegex = / ^ ( .* ?) < ( .* ?) > ( \d + ) ( [ + - ] \d + ) $ / ;
100
100
const match = line . match ( personRegex ) ;
101
101
if ( ! match ) {
102
- throw new Error ( `Failed to parse person line: ${ line } . Make sure to include a name, email, timestamp and timezone offset.` ) ;
102
+ throw new Error (
103
+ `Failed to parse person line: ${ line } . Make sure to include a name, email, timestamp and timezone offset.` ,
104
+ ) ;
103
105
}
104
106
return { name : match [ 1 ] . trim ( ) , email : match [ 2 ] , timestamp : match [ 3 ] } ;
105
107
} ;
@@ -173,7 +175,10 @@ const getCommitData = (contents: CommitContent[]) => {
173
175
}
174
176
175
177
const headerLines = allLines . slice ( 0 , headerEndIndex ) ;
176
- const message = allLines . slice ( headerEndIndex + 1 ) . join ( '\n' ) . trim ( ) ;
178
+ const message = allLines
179
+ . slice ( headerEndIndex + 1 )
180
+ . join ( '\n' )
181
+ . trim ( ) ;
177
182
console . log ( { headerLines, message } ) ;
178
183
179
184
const { tree, parents, authorInfo, committerInfo } = getParsedData ( headerLines ) ;
@@ -374,22 +379,16 @@ const parsePacketLines = (buffer: Buffer): [string[], number] => {
374
379
375
380
// Make sure we don't read past the end of the buffer
376
381
if ( offset + length > buffer . length ) {
377
- throw new Error ( `Invalid packet line length ${ lengthHex } at offset ${ offset } ` ) ;
382
+ throw new Error ( `Invalid packet line length ${ lengthHex } at offset ${ offset } ` ) ;
378
383
}
379
384
380
385
const line = buffer . toString ( 'utf8' , offset + 4 , offset + length ) ;
381
386
lines . push ( line ) ;
382
387
offset += length ; // Move offset to the start of the next line's length prefix
383
388
}
384
389
return [ lines , offset ] ;
385
- }
390
+ } ;
386
391
387
392
exec . displayName = 'parsePush.exec' ;
388
393
389
- export {
390
- exec ,
391
- getCommitData ,
392
- getPackMeta ,
393
- parsePacketLines ,
394
- unpack
395
- } ;
394
+ export { exec , getCommitData , getPackMeta , parsePacketLines , unpack } ;
0 commit comments