20
20
21
21
// MODULES //
22
22
23
+ var join = require ( 'path' ) . join ;
24
+ var spawn = require ( 'child_process' ) . spawnSync ; // eslint-disable-line node/no-sync
25
+ var logger = require ( 'debug' ) ;
23
26
var contains = require ( '@stdlib/assert/contains' ) ;
24
27
var replace = require ( '@stdlib/string/replace' ) ;
25
28
var map = require ( '@stdlib/utils/map' ) ;
@@ -31,11 +34,32 @@ var EXCLUDED_CONTRIBUTORS = require( './excluded_contributors.json' );
31
34
32
35
// VARIABLES //
33
36
37
+ var debug = logger ( 'changelog:generate:format-contributors' ) ;
34
38
var RE_CO_AUTHORED_BY = / c o - a u t h o r e d - b y / i;
39
+ var RESOLVE_NAME_EMAIL_CMD = join ( __dirname , '..' , 'scripts' , 'resolve_name_email.sh' ) ;
35
40
36
41
37
42
// FUNCTIONS //
38
43
44
+ /**
45
+ * Resolves a Git user name and email address according to the .mailmap file.
46
+ *
47
+ * @private
48
+ * @param {string } pair - name and email pair
49
+ * @returns {string } canonical name and email address if found, otherwise the original input
50
+ */
51
+ function resolveNameEmailPair ( pair ) {
52
+ try {
53
+ debug ( 'Attempting to resolve name and email: %s.' , pair ) ;
54
+ return spawn ( RESOLVE_NAME_EMAIL_CMD , [ pair ] , {
55
+ 'stdio' : [ 'pipe' , 'pipe' , 'ignore' ] // stdin, stdout, stderr
56
+ } ) . stdout . toString ( ) ;
57
+ } catch ( err ) {
58
+ debug ( 'Encountered an error resolving name and email: %s.' , err . message ) ;
59
+ return pair ;
60
+ }
61
+ }
62
+
39
63
/**
40
64
* Extracts a list of contributors from a list of commits.
41
65
*
@@ -66,7 +90,8 @@ function extractContributors( commits ) {
66
90
if (
67
91
RE_CO_AUTHORED_BY . test ( mention . action )
68
92
) {
69
- author = replace ( mention . ref , / \s * < [ ^ > ] + > \s * / , '' ) ;
93
+ author = resolveNameEmailPair ( mention . ref ) ;
94
+ author = replace ( author , / \s * < [ ^ > ] + > \s * / , '' ) ;
70
95
if (
71
96
! contains ( out , author ) &&
72
97
! contains ( EXCLUDED_CONTRIBUTORS , author )
0 commit comments