1+ import camelcaseKeys from 'camelcase-keys' ;
12import { StatusCodes } from 'http-status-codes' ;
23
34import { instance , headers } from './setting' ;
45import { _fetch } from './_base' ;
5- import {
6- Commit ,
7- Author ,
8- Status ,
9- HttpNotFoundError ,
10- StatusState ,
11- } from '../models' ;
12-
13- interface CommitData {
14- sha : string ;
15- message : string ;
16- is_pull_request : boolean ;
17- html_url : string ;
18- author ?: {
19- login : string ;
20- avatar_url : string ;
21- date : string ;
22- } ;
23- }
24-
25- export const mapDataToCommit = ( data : CommitData ) : Commit => {
26- let author : Author | undefined ;
27-
28- if ( data . author ) {
29- author = {
30- login : data . author . login ,
31- avatarUrl : data . author . avatar_url ,
32- date : new Date ( data . author . date ) ,
33- } ;
6+ import { Commit , Status , HttpNotFoundError , StatusState } from '../models' ;
7+
8+ export const mapDataToCommit = ( data : any ) : Commit => {
9+ const commit : Commit = camelcaseKeys ( data , { deep : true } ) ;
10+
11+ if ( commit . author ) {
12+ // Convert the type of date field.
13+ commit . author . date = new Date ( data . author . date ) ;
3414 }
3515
36- return {
37- sha : data . sha ,
38- message : data . message ,
39- isPullRequest : data . is_pull_request ,
40- htmlUrl : data . html_url ,
41- author,
42- } ;
16+ return commit ;
4317} ;
4418
45- interface StatusData {
46- context : string ;
47- avatar_url : string ;
48- target_url : string ;
49- state : string ;
50- }
51-
52- const mapDataToStatus = ( data : StatusData ) : Status => {
53- return {
54- context : data . context ,
55- avatarUrl : data . avatar_url ,
56- targetUrl : data . target_url ,
57- state : mapStatusState ( data . state ) ,
58- } ;
19+ const mapDataToStatus = ( data : any ) : Status => {
20+ const status = camelcaseKeys ( data , { deep : true } ) ;
21+ return status ;
5922} ;
6023
6124const mapStatusState = ( state : string ) : StatusState => {
@@ -90,7 +53,7 @@ export const listCommits = async (
9053 }
9154 )
9255 . then ( ( response ) => response . json ( ) )
93- . then ( ( commits ) => commits . map ( ( c : CommitData ) => mapDataToCommit ( c ) ) ) ;
56+ . then ( ( commits ) => commits . map ( ( c : any ) => mapDataToCommit ( c ) ) ) ;
9457
9558 return commits ;
9659} ;
@@ -114,7 +77,7 @@ export const getCommit = async (
11477
11578 const commit : Commit = await response
11679 . json ( )
117- . then ( ( c : CommitData ) => mapDataToCommit ( c ) ) ;
80+ . then ( ( c : any ) => mapDataToCommit ( c ) ) ;
11881
11982 return commit ;
12083} ;
@@ -138,7 +101,7 @@ export const listStatuses = async (
138101
139102 const result = await response . json ( ) . then ( ( d ) => {
140103 let state : StatusState ;
141- const statuses : Status [ ] = d . statuses . map ( ( status : StatusData ) =>
104+ const statuses : Status [ ] = d . statuses . map ( ( status : any ) =>
142105 mapDataToStatus ( status )
143106 ) ;
144107
0 commit comments