Skip to content

Commit

Permalink
Refactor: move contributingUrl into PackageLinks (#7071)
Browse files Browse the repository at this point in the history
  • Loading branch information
isoos authored Sep 28, 2023
1 parent e377d0b commit 73a0df1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
14 changes: 4 additions & 10 deletions app/lib/frontend/templates/package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ d.Node renderPkgInfoBox(PackagePageData data) {
final package = data.package;
final packageLinks = data.packageLinks;

String? documentationUrl = packageLinks.documentationUrl;
if (urls.hideUserProvidedDocUrl(documentationUrl)) {
documentationUrl = null;
}
final dartdocsUrl = urls.pkgDocUrl(
package.name!,
version: data.version.version,
Expand Down Expand Up @@ -83,9 +79,9 @@ d.Node renderPkgInfoBox(PackagePageData data) {
addLink(packageLinks.repositoryUrl, 'Repository',
detectServiceProvider: true);
addLink(packageLinks.issueTrackerUrl, 'View/report issues');
addLink(data.contributingUrl, 'Contributing');
addLink(packageLinks.contributingUrl, 'Contributing');

addLink(documentationUrl, 'Documentation', documentation: true);
addLink(packageLinks.documentationUrl, 'Documentation', documentation: true);
if (data.scoreCard.hasApiDocs) {
addLink(dartdocsUrl, 'API reference', documentation: true);
}
Expand Down Expand Up @@ -333,15 +329,13 @@ Tab? _changelogTab(PackagePageData data) {
Tab? _exampleTab(PackagePageData data) {
if (!data.hasExample) return null;
if (data.asset?.kind != AssetKind.example) return null;
final baseUrl = data.repositoryBaseUrl;

final exampleFilename = data.asset!.path;
final renderedExample = renderFile(
data.asset!,
urlResolverFn: data.urlResolverFn,
);
final url = urls.getRepositoryUrl(baseUrl, exampleFilename!);

final url = data.urlResolverFn?.call(exampleFilename!);
return Tab.withContent(
id: 'example',
title: 'Example',
Expand All @@ -350,7 +344,7 @@ Tab? _exampleTab(PackagePageData data) {
attributes: {'style': 'font-family: monospace'},
child: d.b(
child: url == null
? d.text(exampleFilename)
? d.text(exampleFilename!)
: d.a(
href: url,
target: '_blank',
Expand Down
20 changes: 9 additions & 11 deletions app/lib/package/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1029,16 +1029,22 @@ class PackageLinks {
/// inferred URL from [repositoryUrl].
final String? issueTrackerUrl;

/// The link to `CONTRIBUTING.md` in the git repository (when the repository is verified).
final String? contributingUrl;

/// The inferred base URL that can be used to link files from.
final String? _baseUrl;

PackageLinks._(
this._baseUrl, {
this.homepageUrl,
this.documentationUrl,
String? documentationUrl,
this.repositoryUrl,
this.issueTrackerUrl,
});
this.contributingUrl,
}) : documentationUrl = urls.hideUserProvidedDocUrl(documentationUrl)
? null
: documentationUrl;

factory PackageLinks.infer({
String? homepageUrl,
Expand Down Expand Up @@ -1108,10 +1114,10 @@ class PackagePageData {
repositoryUrl: result.repositoryUrl,
issueTrackerUrl: result.issueTrackerUrl,
documentationUrl: result.documentationUrl,
contributingUrl: result.contributingUrl,
);
}
// Falling back to use URLs from pubspec.yaml.
// TODO: Remove this and return `null` after this release gets stable.
final pubspec = version.pubspec!;
return PackageLinks.infer(
homepageUrl: pubspec.homepage,
Expand All @@ -1121,14 +1127,6 @@ class PackagePageData {
);
}();

late final contributingUrl = scoreCard.panaReport?.result?.contributingUrl;

/// The inferred base URL that can be used to link files from.
late final repositoryBaseUrl = () {
// TODO: use pana's verified repository instead
return packageLinks._baseUrl;
}();

/// The verified repository (or homepage).
late final urlResolverFn =
scoreCard.panaReport?.result?.repository?.resolveUrl ??
Expand Down

0 comments on commit 73a0df1

Please sign in to comment.