Unverified Commit dd97133d authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Remove tool crash git.io link shortener (#99574)

parent c8538873
...@@ -181,7 +181,6 @@ Future<T> runInContext<T>( ...@@ -181,7 +181,6 @@ Future<T> runInContext<T>(
fileSystem: globals.fs, fileSystem: globals.fs,
logger: globals.logger, logger: globals.logger,
flutterProjectFactory: globals.projectFactory, flutterProjectFactory: globals.projectFactory,
client: globals.httpClientFactory?.call() ?? HttpClient(),
), ),
DevFSConfig: () => DevFSConfig(), DevFSConfig: () => DevFSConfig(),
DeviceManager: () => FlutterDeviceManager( DeviceManager: () => FlutterDeviceManager(
......
...@@ -59,16 +59,13 @@ class CrashReporter { ...@@ -59,16 +59,13 @@ class CrashReporter {
required FileSystem fileSystem, required FileSystem fileSystem,
required Logger logger, required Logger logger,
required FlutterProjectFactory flutterProjectFactory, required FlutterProjectFactory flutterProjectFactory,
required HttpClient client,
}) : _fileSystem = fileSystem, }) : _fileSystem = fileSystem,
_logger = logger, _logger = logger,
_flutterProjectFactory = flutterProjectFactory, _flutterProjectFactory = flutterProjectFactory;
_client = client;
final FileSystem _fileSystem; final FileSystem _fileSystem;
final Logger _logger; final Logger _logger;
final FlutterProjectFactory _flutterProjectFactory; final FlutterProjectFactory _flutterProjectFactory;
final HttpClient _client;
/// Prints instructions for filing a bug about the crash. /// Prints instructions for filing a bug about the crash.
Future<void> informUser(CrashDetails details, File crashFile) async { Future<void> informUser(CrashDetails details, File crashFile) async {
...@@ -86,7 +83,6 @@ class CrashReporter { ...@@ -86,7 +83,6 @@ class CrashReporter {
fileSystem: _fileSystem, fileSystem: _fileSystem,
logger: _logger, logger: _logger,
flutterProjectFactory: _flutterProjectFactory, flutterProjectFactory: _flutterProjectFactory,
client: _client,
); );
final String gitHubTemplateURL = await gitHubTemplateCreator.toolCrashIssueTemplateGitHubURL( final String gitHubTemplateURL = await gitHubTemplateCreator.toolCrashIssueTemplateGitHubURL(
......
...@@ -25,16 +25,13 @@ class GitHubTemplateCreator { ...@@ -25,16 +25,13 @@ class GitHubTemplateCreator {
required FileSystem fileSystem, required FileSystem fileSystem,
required Logger logger, required Logger logger,
required FlutterProjectFactory flutterProjectFactory, required FlutterProjectFactory flutterProjectFactory,
required HttpClient client,
}) : _fileSystem = fileSystem, }) : _fileSystem = fileSystem,
_logger = logger, _logger = logger,
_flutterProjectFactory = flutterProjectFactory, _flutterProjectFactory = flutterProjectFactory;
_client = client;
final FileSystem _fileSystem; final FileSystem _fileSystem;
final Logger _logger; final Logger _logger;
final FlutterProjectFactory _flutterProjectFactory; final FlutterProjectFactory _flutterProjectFactory;
final HttpClient _client;
static String toolCrashSimilarIssuesURL(String errorString) { static String toolCrashSimilarIssuesURL(String errorString) {
return 'https://github.com/flutter/flutter/issues?q=is%3Aissue+${Uri.encodeQueryComponent(errorString)}'; return 'https://github.com/flutter/flutter/issues?q=is%3Aissue+${Uri.encodeQueryComponent(errorString)}';
...@@ -110,13 +107,11 @@ $doctorText ...@@ -110,13 +107,11 @@ $doctorText
${_projectMetadataInformation()} ${_projectMetadataInformation()}
'''; ''';
final String fullURL = 'https://github.com/flutter/flutter/issues' return 'https://github.com/flutter/flutter/issues'
'/new' // We split this here to appease our lint that looks for bad "new bug" links. '/new' // We split this here to appease our lint that looks for bad "new bug" links.
'?title=${Uri.encodeQueryComponent(title)}' '?title=${Uri.encodeQueryComponent(title)}'
'&body=${Uri.encodeQueryComponent(body)}' '&body=${Uri.encodeQueryComponent(body)}'
'&labels=${Uri.encodeQueryComponent('tool,severe: crash')}'; '&labels=${Uri.encodeQueryComponent('tool,severe: crash')}';
return _shortURL(fullURL);
} }
/// Provide information about the Flutter project in the working directory, if present. /// Provide information about the Flutter project in the working directory, if present.
...@@ -169,29 +164,4 @@ ${_projectMetadataInformation()} ...@@ -169,29 +164,4 @@ ${_projectMetadataInformation()}
return exception.toString(); return exception.toString();
} }
} }
/// Shorten GitHub URL with git.io API.
///
/// See https://github.blog/2011-11-10-git-io-github-url-shortener.
Future<String> _shortURL(String fullURL) async {
String? url;
try {
_logger.printTrace('Attempting git.io shortener: $fullURL');
final List<int> bodyBytes = utf8.encode('url=${Uri.encodeQueryComponent(fullURL)}');
final HttpClientRequest request = await _client.postUrl(Uri.parse('https://git.io'));
request.headers.set(HttpHeaders.contentLengthHeader, bodyBytes.length.toString());
request.add(bodyBytes);
final HttpClientResponse response = await request.close();
if (response.statusCode == 201) {
url = response.headers[HttpHeaders.locationHeader]?.first;
} else {
_logger.printTrace('Failed to shorten GitHub template URL. Server responded with HTTP status code ${response.statusCode}');
}
} on Exception catch (sendError) {
_logger.printTrace('Failed to shorten GitHub template URL: $sendError');
}
return url ?? fullURL;
}
} }
...@@ -19,7 +19,6 @@ import 'package:http/testing.dart'; ...@@ -19,7 +19,6 @@ import 'package:http/testing.dart';
import 'package:test/fake.dart'; import 'package:test/fake.dart';
import '../src/common.dart'; import '../src/common.dart';
import '../src/fake_http_client.dart';
import '../src/fake_process_manager.dart'; import '../src/fake_process_manager.dart';
void main() { void main() {
...@@ -83,7 +82,6 @@ void main() { ...@@ -83,7 +82,6 @@ void main() {
fileSystem: fs, fileSystem: fs,
logger: logger, logger: logger,
flutterProjectFactory: FlutterProjectFactory(fileSystem: fs, logger: logger), flutterProjectFactory: FlutterProjectFactory(fileSystem: fs, logger: logger),
client: FakeHttpClient.any(),
); );
final File file = fs.file('flutter_00.log'); final File file = fs.file('flutter_00.log');
......
...@@ -14,9 +14,6 @@ import 'package:flutter_tools/src/reporting/github_template.dart'; ...@@ -14,9 +14,6 @@ import 'package:flutter_tools/src/reporting/github_template.dart';
import '../src/common.dart'; import '../src/common.dart';
import '../src/context.dart'; import '../src/context.dart';
import '../src/fake_http_client.dart';
const String _kShortURL = 'https://www.example.com/short';
void main() { void main() {
BufferLogger logger; BufferLogger logger;
...@@ -157,41 +154,10 @@ void main() { ...@@ -157,41 +154,10 @@ void main() {
error = ArgumentError('argument error message'); error = ArgumentError('argument error message');
}); });
testUsingContext('shortened', () async { testUsingContext('shows GitHub issue URL', () async {
final GitHubTemplateCreator creator = GitHubTemplateCreator(
fileSystem: fs,
logger: logger,
client: FakeHttpClient.list(<FakeRequest>[
FakeRequest(Uri.parse('https://git.io'), method: HttpMethod.post, response: const FakeResponse(
statusCode: 201,
headers: <String, List<String>>{
HttpHeaders.locationHeader: <String>[_kShortURL],
}
))
]),
flutterProjectFactory: FlutterProjectFactory(
fileSystem: fs,
logger: logger,
),
);
expect(
await creator.toolCrashIssueTemplateGitHubURL(command, error, stackTrace, doctorText),
_kShortURL
);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('with network failure', () async {
final GitHubTemplateCreator creator = GitHubTemplateCreator( final GitHubTemplateCreator creator = GitHubTemplateCreator(
fileSystem: fs, fileSystem: fs,
logger: logger, logger: logger,
client: FakeHttpClient.list(<FakeRequest>[
FakeRequest(Uri.parse('https://git.io'), method: HttpMethod.post, response: const FakeResponse(
statusCode: 500,
))
]),
flutterProjectFactory: FlutterProjectFactory( flutterProjectFactory: FlutterProjectFactory(
fileSystem: fs, fileSystem: fs,
logger: logger, logger: logger,
...@@ -207,7 +173,6 @@ void main() { ...@@ -207,7 +173,6 @@ void main() {
'eport%0A%60%60%60%0A%0A%23%23+Flutter+Application+Metadata%0ANo+pubspec+in+working+d' 'eport%0A%60%60%60%0A%0A%23%23+Flutter+Application+Metadata%0ANo+pubspec+in+working+d'
'irectory.%0A&labels=tool%2Csevere%3A+crash' 'irectory.%0A&labels=tool%2Csevere%3A+crash'
); );
expect(logger.traceText, contains('Failed to shorten GitHub template URL'));
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(), FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
...@@ -217,7 +182,6 @@ void main() { ...@@ -217,7 +182,6 @@ void main() {
final GitHubTemplateCreator creator = GitHubTemplateCreator( final GitHubTemplateCreator creator = GitHubTemplateCreator(
fileSystem: fs, fileSystem: fs,
logger: logger, logger: logger,
client: FakeHttpClient.any(),
flutterProjectFactory: FlutterProjectFactory( flutterProjectFactory: FlutterProjectFactory(
fileSystem: fs, fileSystem: fs,
logger: logger, logger: logger,
......
...@@ -56,26 +56,6 @@ String _toMethodString(HttpMethod method) { ...@@ -56,26 +56,6 @@ String _toMethodString(HttpMethod method) {
} }
} }
/// Override the creation of all [HttpClient] objects with a zone injection.
///
/// This should only be used when the http client cannot be set directly, such as
/// when testing `package:http` code.
Future<void> overrideHttpClients(Future<void> Function() callback, FakeHttpClient httpClient) async {
final HttpOverrides overrides = _FakeHttpClientOverrides(httpClient);
await HttpOverrides.runWithHttpOverrides(callback, overrides);
}
class _FakeHttpClientOverrides extends HttpOverrides {
_FakeHttpClientOverrides(this.httpClient);
final FakeHttpClient httpClient;
@override
HttpClient createHttpClient(SecurityContext? context) {
return httpClient;
}
}
/// Create a fake request that configures the [FakeHttpClient] to respond /// Create a fake request that configures the [FakeHttpClient] to respond
/// with the provided [response]. /// with the provided [response].
/// ///
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment