From d8b18e80902f17a2233e25ffe40ddd1c4a8c857b Mon Sep 17 00:00:00 2001 From: pq Date: Tue, 18 Jul 2023 15:46:41 -0700 Subject: [PATCH] remove `package:github` dependent code --- pubspec.yaml | 1 - tool/canonical/gh_labels.dart | 64 ------------------------------- tool/canonical/scorecard.dart | 18 --------- tool/gh/get_labels.dart | 55 -------------------------- tool/github.dart | 38 ------------------ tool/query.dart | 72 ----------------------------------- tool/scorecard.dart | 22 +---------- 7 files changed, 1 insertion(+), 269 deletions(-) delete mode 100644 tool/canonical/gh_labels.dart delete mode 100644 tool/gh/get_labels.dart delete mode 100644 tool/github.dart delete mode 100644 tool/query.dart diff --git a/pubspec.yaml b/pubspec.yaml index 4af2da458..35d879133 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -23,7 +23,6 @@ dependencies: dev_dependencies: benchmark_harness: ^2.0.0 cli_util: ^0.4.0 - github: ^9.0.0 lints: ^2.0.0 markdown: ^7.0.0 matcher: ^0.12.10 diff --git a/tool/canonical/gh_labels.dart b/tool/canonical/gh_labels.dart deleted file mode 100644 index 453683d7c..000000000 --- a/tool/canonical/gh_labels.dart +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:convert'; - -import 'package:args/args.dart'; -import 'package:github/github.dart'; -import 'package:http/http.dart' as http; -import 'package:linter/src/utils.dart'; - -import '../github.dart'; - -/// Outputs a list of issues whose GH issue tags need updating. -Future main(List args) async { - var parser = ArgParser() - ..addOption('token', abbr: 't', help: 'Specifies a GitHub auth token.'); - ArgResults options; - try { - options = parser.parse(args); - } on FormatException catch (err) { - printUsage(parser, err.message); - return; - } - - var client = http.Client(); - var req = await client.get( - Uri.parse('https://dart-lang.github.io/linter/lints/machine/rules.json')); - - var token = options['token']; - var auth = token is String - ? Authentication.withToken(token) - : const Authentication.anonymous(); - - var machine = json.decode(req.body) as List; - var rules = machine - .map((e) => MapEntry(e['name'] as String, e['sets'] as List)) - .toList(); - - var issues = await getLinterIssues(auth: auth); - for (var issue in issues) { - var title = issue.title; - for (var rule in rules) { - if (title.contains(rule.key)) { - var sets = rule.value; - for (var set in sets) { - if (!issue.labels.any((label) => label.name.startsWith('set-'))) { - printToConsole('${issue.htmlUrl} => set-$set'); - } - } - } - } - } -} - -void printUsage(ArgParser parser, [String? error]) { - var message = error ?? - 'Query lint rules for containing rule sets and relevant GH issues.'; - - printToConsole('''$message -Usage: query.dart rule_name -${parser.usage} -'''); -} diff --git a/tool/canonical/scorecard.dart b/tool/canonical/scorecard.dart index 78397214b..53eafb496 100644 --- a/tool/canonical/scorecard.dart +++ b/tool/canonical/scorecard.dart @@ -11,7 +11,6 @@ import 'package:analyzer/dart/ast/visitor.dart'; import 'package:analyzer/src/lint/config.dart'; // ignore: implementation_imports import 'package:analyzer/src/lint/registry.dart'; // ignore: implementation_imports import 'package:analyzer/src/lint/state.dart'; // ignore: implementation_imports -import 'package:github/github.dart'; import 'package:http/http.dart' as http; import 'package:linter/src/analyzer.dart'; import 'package:linter/src/rules.dart'; @@ -139,7 +138,6 @@ class Detail { static const Detail fix = Detail('fix'); static const Detail bulk = Detail('bulk'); static const Detail status = Detail('status'); - static const Detail bugs = Detail('bug refs', header: Header.left); final String name; final Header header; const Detail(this.name, {this.header = Header.center}); @@ -161,7 +159,6 @@ class LintScore { State state; List ruleSets; - List bugReferences; LintScore({ required this.name, @@ -170,7 +167,6 @@ class LintScore { required this.hasBulkFix, required this.state, required this.ruleSets, - required this.bugReferences, }); bool get inCore => ruleSets.contains('core'); @@ -198,8 +194,6 @@ class LintScore { sb.write(' $status |'); case Detail.status: sb.write('${!state.isStable ? ' **${state.label}** ' : ""} |'); - case Detail.bugs: - sb.write(' ${bugReferences.join(", ")} |'); } } return sb.toString(); @@ -267,9 +261,6 @@ class ScoreCard { var lintsWithAssists = _getLintsWithAssists(); var lintsWithFixes = await _getLintsWithFixes(); var lintsWithBulkFixes = await _getLintsWithBulkFixes(); - // var issues = await _getIssues(); - // var bugs = issues.where(_isBug).toList(); - var bugs = []; var coreRuleset = await _readCoreLints(); var recommendedRuleset = await _readRecommendedLints(); @@ -292,14 +283,6 @@ class ScoreCard { continue; } - var bugReferences = []; - for (var bug in bugs) { - var title = bug.title; - if (title.contains(lint.name)) { - bugReferences.add('#${bug.number}'); - } - } - var lintName = lint.name; scorecard.add(LintScore( name: lintName, @@ -308,7 +291,6 @@ class ScoreCard { hasBulkFix: lintsWithBulkFixes.contains(lintName), state: lint.state, ruleSets: ruleSets, - bugReferences: bugReferences, )); } diff --git a/tool/gh/get_labels.dart b/tool/gh/get_labels.dart deleted file mode 100644 index abdfe9937..000000000 --- a/tool/gh/get_labels.dart +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:args/args.dart'; -import 'package:github/github.dart'; -import 'package:linter/src/utils.dart'; - -import '../github.dart'; - -/// Outputs a list of labels. -Future main(List args) async { - var parser = ArgParser() - ..addOption('token', abbr: 't', help: 'Specifies a GitHub auth token.') - ..addOption('owner', - abbr: 'o', help: 'Specifies a GitHub repo owner (e.g., dart-lang).') - ..addOption('name', - abbr: 'n', help: 'Specifies a GitHub repo name (e.g., sdk).'); - - ArgResults options; - try { - options = parser.parse(args); - } on FormatException catch (err) { - printUsage(parser, err.message); - return; - } - - var owner = options['owner']; - if (owner is! String) { - printUsage(parser, 'Must specify repo owner.'); - return; - } - var name = options['name']; - if (name is! String) { - printUsage(parser, 'Must specify repo name.'); - return; - } - - var token = options['token']; - var auth = token is String - ? Authentication.withToken(token) - : const Authentication.anonymous(); - var labels = await getLabels(owner: owner, name: name, auth: auth); - for (var label in labels) { - printToConsole(label.name); - } -} - -void printUsage(ArgParser parser, [String? error]) { - var message = error ?? 'Get labels for a given GitHub repo.'; - printToConsole('''$message -Usage: get_labels.dart rule_name -${parser.usage} -'''); -} diff --git a/tool/github.dart b/tool/github.dart deleted file mode 100644 index b621aeb4a..000000000 --- a/tool/github.dart +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'package:github/github.dart'; -import 'package:linter/src/utils.dart'; - -Future> getLabels({ - required String owner, - required String name, - required Authentication auth, -}) async { - var github = GitHub(auth: auth); - var slug = RepositorySlug(owner, name); - try { - return github.issues.listLabels(slug).toList(); - } on Exception catch (e) { - printToConsole('exception caught fetching GitHub labels'); - printToConsole(e); - printToConsole('(defaulting to an empty list)'); - return Future.value([]); - } -} - -Future> getLinterIssues({required Authentication auth}) async { - var github = GitHub(auth: auth); - var slug = RepositorySlug('dart-lang', 'linter'); - try { - return github.issues.listByRepo(slug).toList(); - } on Exception catch (e) { - printToConsole('exception caught fetching GitHub issues'); - printToConsole(e); - printToConsole('(defaulting to an empty list)'); - return Future.value([]); - } -} - -bool isBug(Issue issue) => issue.labels.map((l) => l.name).contains('bug'); diff --git a/tool/query.dart b/tool/query.dart deleted file mode 100644 index ed98d9640..000000000 --- a/tool/query.dart +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:convert'; - -import 'package:args/args.dart'; -import 'package:github/github.dart'; -import 'package:http/http.dart' as http; -import 'package:linter/src/utils.dart'; - -import 'github.dart'; - -Future main(List args) async { - var parser = ArgParser() - ..addOption('token', abbr: 't', help: 'Specifies a GitHub auth token.'); - ArgResults options; - try { - options = parser.parse(args); - } on FormatException catch (err) { - printUsage(parser, err.message); - return; - } - - var rules = options.rest; - if (rules.isEmpty) { - printUsage(parser, 'At least one rule needs to be specified.'); - return; - } - - var client = http.Client(); - var req = await client.get( - Uri.parse('https://dart-lang.github.io/linter/lints/machine/rules.json')); - - var token = options['token']; - var auth = token is String - ? Authentication.withToken(token) - : const Authentication.anonymous(); - - var machine = json.decode(req.body) as Iterable; - - for (var rule in rules) { - for (var entry in machine) { - if (entry['name'] == rule) { - printToConsole('https://dart-lang.github.io/linter/lints/$rule.html'); - printToConsole(''); - printToConsole('contained in: ${entry["sets"]}'); - var issues = await getLinterIssues(auth: auth); - for (var issue in issues) { - var title = issue.title; - if (title.contains(rule)) { - printToConsole('issue: ${issue.title}'); - printToConsole( - 'labels: ${issue.labels.map((e) => e.name).join(", ")}'); - printToConsole(issue.htmlUrl); - printToConsole(''); - } - } - } - } - } -} - -void printUsage(ArgParser parser, [String? error]) { - var message = error ?? - 'Query lint rules for containing rule sets and relevant GH issues.'; - - printToConsole('''$message -Usage: query.dart rule_name -${parser.usage} -'''); -} diff --git a/tool/scorecard.dart b/tool/scorecard.dart index 5c8e08d05..3f6840830 100644 --- a/tool/scorecard.dart +++ b/tool/scorecard.dart @@ -8,14 +8,12 @@ import 'package:analyzer/dart/ast/ast.dart'; import 'package:analyzer/dart/ast/visitor.dart'; import 'package:analyzer/src/lint/registry.dart'; import 'package:analyzer/src/lint/state.dart'; -import 'package:github/github.dart'; import 'package:http/http.dart' as http; import 'package:linter/src/analyzer.dart'; import 'package:linter/src/rules.dart'; import 'package:linter/src/utils.dart'; import 'crawl.dart'; -import 'github.dart'; import 'parse.dart'; import 'since.dart'; @@ -28,7 +26,6 @@ void main() async { Detail.flutterUser, Detail.flutterRepo, Detail.status, - Detail.bugs, ]; printToConsole(scorecard.asMarkdown(details)); @@ -108,7 +105,6 @@ class Detail { static const Detail flutterUser = Detail('flutter user'); static const Detail flutterRepo = Detail('flutter repo'); static const Detail status = Detail('status'); - static const Detail bugs = Detail('bug refs', header: Header.left); final String name; final Header header; const Detail(this.name, {this.header = Header.center}); @@ -130,14 +126,12 @@ class LintScore { SinceInfo? since; List ruleSets; - List bugReferences; LintScore( {required this.name, required this.hasFix, required this.state, required this.ruleSets, - required this.bugReferences, this.since}); String get _ruleSets => ruleSets.isNotEmpty ? ' $ruleSets' : ''; @@ -160,8 +154,6 @@ class LintScore { '${ruleSets.contains('flutter_repo') ? " $checkMark" : ""} |'); case Detail.status: sb.write('${!state.isStable ? ' **${state.label}** ' : ""} |'); - case Detail.bugs: - sb.write(' ${bugReferences.join(", ")} |'); } } return sb.toString(); @@ -211,9 +203,6 @@ class ScoreCard { var flutterRuleset = await flutterRules; var flutterRepoRuleset = await flutterRepoRules; - var issues = await getLinterIssues(auth: const Authentication.anonymous()); - var bugs = issues.where(isBug).toList(); - var scorecard = ScoreCard(); for (var lint in registeredLints!) { var ruleSets = []; @@ -224,22 +213,13 @@ class ScoreCard { ruleSets.add('flutter_repo'); } - var bugReferences = []; - for (var bug in bugs) { - var title = bug.title; - if (title.contains(lint.name)) { - bugReferences.add('#${bug.number}'); - } - } - scorecard.add(LintScore( name: lint.name, hasFix: lintsWithFixes.contains(lint.name) || lintsWithAssists.contains(lint.name), state: lint.state, ruleSets: ruleSets, - since: sinceMap[lint.name], - bugReferences: bugReferences)); + since: sinceMap[lint.name])); } return scorecard;