blob: 10534a03b3ad6658df85a192fe53fbd772059e46 [file] [log] [blame]
// 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 'dart:io';
import 'package:path/path.dart' as path;
import '../github.dart';
import '../repo.dart';
import '../utils.dart';
Future<Map<Package, List<GitFile>>> packagesWithoutChangelog(
Github github) async {
final repo = Repository();
final packages = repo.locatePackages();
final files = await github.listFilesForPR();
var packagesWithoutChangedChangelog =
collectPackagesWithoutChangelogChanges(packages, files);
print('Collecting files without license headers in those packages:');
var packagesWithChanges = <Package, List<GitFile>>{};
for (final file in files) {
for (final package in packagesWithoutChangedChangelog) {
if (fileNeedsEntryInChangelog(package, file.relativePath)) {
(changedFiles) => [...changedFiles, file],
ifAbsent: () => [file],
Done, found ${packagesWithChanges.length} packages with a need for a changelog.''');
return packagesWithChanges;
List<Package> collectPackagesWithoutChangelogChanges(
List<Package> packages, List<GitFile> files) {
print('Collecting packages without changed changelogs:');
final packagesWithoutChangedChangelog = packages
.where((package) => package.changelog.exists)
.where((package) => !files
.map((e) => e.relativePath)
print('Done, found ${packagesWithoutChangedChangelog.length} packages.');
return packagesWithoutChangedChangelog;
bool fileNeedsEntryInChangelog(Package package, String file) {
final directoryPath =;
final directory = path.relative(directoryPath, from: Directory.current.path);
final isInPackage = path.isWithin(directory, file);
final isInLib = path.isWithin(path.join(directory, 'lib'), file);
final isInBin = path.isWithin(path.join(directory, 'bin'), file);
final isPubspec = file.endsWith('pubspec.yaml');
final isReadme = file.endsWith('');
return isInPackage && (isInLib || isInBin || isPubspec || isReadme);