Skip to content

Commit

Permalink
Tool for visualizing the wiki (#2983)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hixie authored Aug 23, 2023
1 parent 12d1e21 commit 536a174
Show file tree
Hide file tree
Showing 12 changed files with 787 additions and 51 deletions.
57 changes: 43 additions & 14 deletions dev/githubanalysis/lib/issue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ import 'utils.dart';
const List<String> priorities = <String>['P0', 'P1', 'P2', 'P3'];

class FullIssue {
FullIssue(this.repo, this.issueNumber, this._metadata, this.comments, this.reactions,
{this.redirect, this.isDeleted = false}) {
FullIssue(
this.repo,
this.issueNumber,
this._metadata,
this.comments,
this.reactions, {
this.redirect,
this.isDeleted = false,
}) {
_labels = _metadata?.labels.map<String>((final IssueLabel label) => label.name).toSet();
if (_labels != null) {
final Set<String> matches = priorities.toSet().intersection(_labels!);
Expand Down Expand Up @@ -82,8 +89,14 @@ class FullIssue {
});
final Map<String, Object?> data = json.decode(cacheData)! as Map<String, Object?>;
if (data['redirect'] != null) {
return FullIssue(repo, issueNumber, null, const <IssueComment>[], const <Reaction>[],
redirect: data['redirect']! as String);
return FullIssue(
repo,
issueNumber,
null,
const <IssueComment>[],
const <Reaction>[],
redirect: data['redirect']! as String,
);
}
if (data['deleted'] == true) {
return FullIssue(repo, issueNumber, null, const <IssueComment>[], const <Reaction>[], isDeleted: true);
Expand All @@ -109,7 +122,8 @@ class FullIssue {
..writeln('Issue $issueNumber (${metadata.state}): ${metadata.title}')
..writeln(metadata.htmlUrl)
..writeln(
'Created by ${metadata.user!.login} on ${metadata.createdAt}, last updated on ${metadata.updatedAt}.');
'Created by ${metadata.user!.login} on ${metadata.createdAt}, last updated on ${metadata.updatedAt}.',
);
if (metadata.isClosed) {
result.writeln('Closed by ${metadata.closedBy?.login} on ${metadata.closedAt}.');
if (metadata.closedBy != null) {
Expand Down Expand Up @@ -158,8 +172,13 @@ class FullIssue {
}
}

Future<void> fetchAllIssues(final GitHub github, final Directory cache, final RepositorySlug repo,
final Duration issueMaxAge, final Map<int, FullIssue> results) async {
Future<void> fetchAllIssues(
final GitHub github,
final Directory cache,
final RepositorySlug repo,
final Duration issueMaxAge,
final Map<int, FullIssue> results,
) async {
int index = 1;
int issues = 0;
int prs = 0;
Expand Down Expand Up @@ -205,17 +224,22 @@ Future<void> fetchAllIssues(final GitHub github, final Directory cache, final Re
}
}
await rateLimit(
github,
'${repo.fullName}: #$index${lastIssueNumber > 0 ? " of ${maxKnown ? "" : "~"}$lastIssueNumber" : ""} ($issues issues; $prs PRs; $invalid errors)',
'issue #${index + 1}');
github,
'${repo.fullName}: #$index${lastIssueNumber > 0 ? " of ${maxKnown ? "" : "~"}$lastIssueNumber" : ""} ($issues issues; $prs PRs; $invalid errors)',
'issue #${index + 1}',
);
index += 1;
}
await lastIssueNumberFile.writeAsString(lastIssueNumber.toString());
stdout.write('\x1B[K\r');
}

Future<void> updateAllIssues(
final GitHub github, final Directory cache, final RepositorySlug repo, final Map<int, FullIssue> issues) async {
final GitHub github,
final Directory cache,
final RepositorySlug repo,
final Map<int, FullIssue> issues,
) async {
final Set<int> pendingIssues = issues.isEmpty ? <int>{} : issues.keys.toSet();
int highestKnownIssue = pendingIssues.isEmpty ? 0 : (pendingIssues.toList()..sort()).last;
final File updateStampFile = cacheFileFor(cache, <String>['issue', repo.owner, repo.name, 'last-update']);
Expand Down Expand Up @@ -262,8 +286,10 @@ Future<void> updateAllIssues(
issueNumber: summary.number,
cacheEpoch: summary.updatedAt,
);
assert(!issue.isValid || !issue.metadata.updatedAt!.isBefore(summary.updatedAt!),
'invariant violation\nOLD DATA:\n${json.encode(issue.metadata.toJson())}\nNEW DATA:\n${json.encode(summary.toJson())}');
assert(
!issue.isValid || !issue.metadata.updatedAt!.isBefore(summary.updatedAt!),
'invariant violation\nOLD DATA:\n${json.encode(issue.metadata.toJson())}\nNEW DATA:\n${json.encode(summary.toJson())}',
);
if (issue.issueNumber > highestKnownIssue) {
for (int index = highestKnownIssue; index < issue.issueNumber; index += 1) {
pendingIssues.add(index);
Expand All @@ -286,7 +312,10 @@ Future<void> updateAllIssues(
int count = 0;
for (final int issueNumber in pendingIssues) {
await rateLimit(
github, '${repo.fullName}: $count / ${pendingIssues.length} missing issues checked', 'issue #$issueNumber');
github,
'${repo.fullName}: $count / ${pendingIssues.length} missing issues checked',
'issue #$issueNumber',
);
try {
issues[issueNumber] = await FullIssue.load(
cache: cache,
Expand Down
Loading

0 comments on commit 536a174

Please sign in to comment.