Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions bin/repair-renamed-labels
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ try {
const byRepo = new Map();
for (const row of stored) byRepo.set(row.repo, [...(byRepo.get(row.repo) ?? []), row.title]);

const renames = [];
let renames = [];
for (const [repo, titles] of byRepo) {
let live;
try {
Expand All @@ -70,8 +70,9 @@ try {
const data = await git.github.issues
.listLabelsOnIssue({ ...split(repo), issue_number: number })
.then(res => res.data)
// deleted or moved away: it says nothing about the new name
.catch(err => (err.status === 404 ? null : Promise.reject(err)));
// deleted (410) or moved away (404): it says nothing about
// the new name
.catch(err => ([404, 410].includes(err.status) ? null : Promise.reject(err)));
if (!data) continue;
const mine = (await dbManager.getLabels(repo, number)).map(l => l.data.title);
const fresh = data.map(l => l.name).filter(name => !mine.includes(name));
Expand All @@ -92,6 +93,21 @@ try {
}
}

// two old labels pointing at one new name: an item carrying both (FoF
// and squad-carpenter, now carpenter) can't say which was renamed
const key = r => `${r.repo}#${r.to.toLowerCase()}`;
const counts = new Map();
for (const r of renames) counts.set(key(r), (counts.get(key(r)) ?? 0) + 1);
for (const r of renames.filter(r => counts.get(key(r)) > 1)) {
console.log(
'%s: "%s" -> "%s" shares its new name with another, left alone',
r.repo,
r.from,
r.to
);
}
renames = renames.filter(r => counts.get(key(r)) === 1);

if (apply) {
for (const { repo, from, to } of renames) await dbManager.renameLabel(repo, from, to);
const slug = name =>
Expand Down
Loading