Skip to content

Commit 3fa9f79

Browse files
parloughCommit Queue
authored andcommitted
[tools/deps] Adjust commit messages to link to correct repositories
Prevents auto-linking to incorrect issue when the tool's output is committed. Do this by removing the hash from `#number` in the commit message, and replacing the PR link at the of the message with a fully qualified reference that resolves to the correct repository on GitHub. An example of the new output: ``` yaml (https://github.com/dart-lang/yaml/compare/98a3aab..509fd72): 509fd72 Mon Dec 11 16:37:13 2023 -0800 Kevin Moore update lints, require Dart 3.0 (dart-archive/yaml#156) yaml_edit (https://github.com/dart-lang/yaml_edit/compare/9b9d33c..47eb20e): 47eb20e Mon Jan 1 13:13:22 2024 +0000 dependabot[bot] Bump actions/stale from 8.0.0 to 9.0.0 (dart-archive/yaml_edit#63) a39ec39 Wed Dec 20 11:51:28 2023 -0800 Kevin Moore blast_repo fixes (dart-archive/yaml_edit#62) ``` Closes #53857 Change-Id: I23e9d556c69445189a916ce33091a9c77ae15941 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/344361 Commit-Queue: Nate Bosch <[email protected]> Reviewed-by: Nate Bosch <[email protected]> Auto-Submit: Parker Lougheed <[email protected]> Reviewed-by: Devon Carew <[email protected]>
1 parent ef75007 commit 3fa9f79

File tree

1 file changed

+52
-17
lines changed

1 file changed

+52
-17
lines changed

tools/rev_sdk_deps.dart

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
127152
Set<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

Comments
 (0)