@@ -88,20 +88,31 @@ void main(List<String> args) async {
8888 print ('Revisions updated by `dart tools/rev_sdk_deps.dart`.' );
8989 print ('' );
9090
91- for (var entry in revDepsToCommits.entries) {
92- final dep = entry.key;
93- final commit = entry.value;
94-
91+ for (final MapEntry (key: dep, value: commit) in revDepsToCommits.entries) {
9592 final git = GitHelper (dep.relativePath);
9693
97- var gitLog = await git.calculateUnsyncedCommits ();
98- var currentHash = await gclient.getHash (dep);
94+ final gitLog = await git.calculateUnsyncedCommits ();
95+ final currentHash = await gclient.getHash (dep);
96+
97+ final gitHubRepo = dep.gitHubRepoIdentifier;
98+
99+ // Construct and print out the GitHub diff URL.
100+ print ('${dep .name } (${dep .gitHubDiffUrl (currentHash , commit )}):' );
99101
100- // Construct the github diff URL.
101- print ('${dep .name } (${dep .getGithubDiffUrl (currentHash , commit )}):' );
102+ /// Qualify or wrap the GitHub issue references within [commitMessage] .
103+ String replaceHashReferences (String commitMessage) => commitMessage
104+ .replaceAllMapped (
105+ _mergeCommitPullRequestReference,
106+ (m) => '($gitHubRepo #${m [1 ]})' ,
107+ )
108+ .replaceAllMapped (_issueHashReference, (m) => '`${m [0 ]}`' );
102109
103- // Print out the new commits.
104- print (gitLog.split ('\n ' ).map ((l) => ' $l ' ).join ('\n ' ).trimRight ());
110+ // Format and print out the message header of each new commit.
111+ final newCommitHeaders = [
112+ for (final commitHeader in gitLog.split ('\n ' ))
113+ ' ${replaceHashReferences (commitHeader )}' ,
114+ ];
115+ print (newCommitHeaders.join ('\n ' ).trimRight ());
105116
106117 // Update the DEPS file.
107118 await gclient.setHash (dep, commit);
@@ -123,6 +134,20 @@ void main(List<String> args) async {
123134 }
124135}
125136
137+ /// A regex that matches the final PR reference of a merge commit header.
138+ ///
139+ /// Allows replacing the PR reference with a repository qualified reference,
140+ /// so that GitHub auto links to the correct repository instead of
141+ /// an irrelevant issue or PR on the SDK repository.
142+ final RegExp _mergeCommitPullRequestReference = RegExp (r'\(#?(\d+)\)$' );
143+
144+ /// A regex that matches any non-qualified issue or PR references
145+ /// within a commit message, such as `#123` .
146+ ///
147+ /// Allows replacing or wrapping the potential issue or PR references so that
148+ /// GitHub doesn't autolink to an irrelevant issue or PR on the SDK repository.
149+ final RegExp _issueHashReference = RegExp (r'\B#\d+' );
150+
126151// By convention, pinned deps are deps with an eol comment.
127152Set <String > calculatePinnedDeps () {
128153 final packageRevision = RegExp (r'"(\w+)_rev":' );
@@ -266,24 +291,34 @@ class PackageDependency {
266291
267292 String get relativePath => entry.substring ('sdk/' .length);
268293
269- String getGithubDiffUrl (String fromCommit, String toCommit) {
270- // https://github.com/dart-lang/<repo>/compare/<old>..<new>
271- final from = fromCommit.substring (0 , 7 );
272- final to = toCommit.substring (0 , 7 );
273-
294+ /// The identifier of the GitHub repository this dependency is from.
295+ ///
296+ /// For example: `dart-lang/test` .
297+ String get gitHubRepoIdentifier {
274298 var repo = url.substring (url.lastIndexOf ('/' ) + 1 );
275299 if (repo.endsWith ('git' )) {
276300 repo = repo.substring (0 , repo.length - '.git' .length);
277301 }
278302
279- var org = 'dart-lang' ;
303+ final String org ;
280304 if (url.contains ('/external/' )) {
281305 // https://dart.googlesource.com/external/github.com/google/webdriver.dart.git
282306 final parts = url.split ('/' );
283307 org = parts[parts.length - 2 ];
308+ } else {
309+ org = 'dart-lang' ;
284310 }
285311
286- return 'https://github.com/$org /$repo /compare/$from ..$to ' ;
312+ return '$org /$repo ' ;
313+ }
314+
315+ /// The URL of the GitHub comparison view between [fromCommit] and [toCommit] .
316+ Uri gitHubDiffUrl (String fromCommit, String toCommit) {
317+ // https://github.com/dart-lang/<repo>/compare/<old>..<new>
318+ final from = fromCommit.substring (0 , 7 );
319+ final to = toCommit.substring (0 , 7 );
320+
321+ return Uri .https ('github.com' , '$gitHubRepoIdentifier /compare/$from ..$to ' );
287322 }
288323
289324 @override
0 commit comments