@@ -11,6 +11,11 @@ import glob from 'fast-glob';
11
11
import fetch from 'node-fetch' ;
12
12
import frontMatter from 'front-matter' ;
13
13
import markdownRenderer from '../markdown-renderer' ;
14
+ import simplegit from 'simple-git/promise' ;
15
+
16
+ // ingored by git
17
+ // generated in build-data/file-contrbutors.ts by build-data npm task
18
+ import * as GITHUB_COMMITS from '../../data/github-commits.json' ;
14
19
15
20
export default {
16
21
title : 'Build static pages' ,
@@ -54,24 +59,10 @@ const readMarkdown = (path: string): Promise<string> =>
54
59
} ) ;
55
60
56
61
const getGitHubData = async ( filePath : string ) => {
57
- const [ , path ] = / ^ .+ \/ ( s r c \/ ( l 1 0 n \/ ) ? p a g e s \/ .+ \. m d ) $ / . exec ( filePath ) ;
58
- const since = new Date ( '2019-01-23' ) . toISOString ( ) ;
62
+ const [ , path ] = / ^ .+ \/ ( s r c \/ p a g e s \/ .+ \. m d ) $ / . exec ( filePath ) ;
59
63
60
64
try {
61
- const request = await fetch ( url . format ( {
62
- protocol : 'https' ,
63
- hostname : 'api.github.com' ,
64
- pathname : 'repos/ionic-team/ionic-docs/commits' ,
65
- query : {
66
- access_token : process . env . GITHUB_TOKEN ,
67
- since,
68
- path
69
- }
70
- } ) ) ;
71
-
72
- const commits = await request . json ( ) ;
73
- const contributors = Array . from ( new Set ( commits . map ( commit => commit . author . login ) ) ) ;
74
- const lastUpdated = commits . length ? commits [ 0 ] . commit . author . date : since ;
65
+ const { contributors, lastUpdated } = await getFileContributors ( filePath ) ;
75
66
return {
76
67
path,
77
68
contributors,
@@ -81,7 +72,19 @@ const getGitHubData = async (filePath: string) => {
81
72
return {
82
73
path,
83
74
contributors : [ ] ,
84
- lastUpdated : since
75
+ lastUpdated : new Date ( '2019-01-23' ) . toISOString ( )
85
76
} ;
86
77
}
87
78
} ;
79
+
80
+ async function getFileContributors ( filename ) {
81
+ return simplegit ( ) . log ( { file : filename } ) . then ( status => ( {
82
+ contributors : Array . from ( new Set ( status . all . map ( commit =>
83
+ // only add the user ID if we can find it based on the commit hash
84
+ GITHUB_COMMITS [ commit . hash ] ? GITHUB_COMMITS [ commit . hash ] . id : null
85
+ // filter out null users
86
+ ) . filter ( user => ! ! user ) ) ) ,
87
+ lastUpdated : status . latest . date
88
+ } )
89
+ ) ;
90
+ }
0 commit comments