Skip to content

Commit a5d25ea

Browse files
authored
Merge pull request piceaTech#160 from alystair/master
Feature: transfer label descriptions
2 parents b28ceec + 91bd576 commit a5d25ea

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

sample_settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export default {
4949
useReplacementIssuesForCreationFails: true,
5050
useIssuesForAllMergeRequests: false,
5151
filterByLabel: null,
52+
trimOversizedLabelDescriptions: false,
5253
skipMergeRequestStates: [],
5354
skipMatchingComments: [],
5455
mergeRequests: {

src/githubHelper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export interface MilestoneImport {
4949
export interface SimpleLabel {
5050
name: string;
5151
color: string;
52+
description: string;
5253
}
5354

5455
export interface SimpleMilestone {
@@ -765,6 +766,7 @@ export class GithubHelper {
765766
repo: this.githubRepo,
766767
name: label.name,
767768
color: label.color.substring(1), // remove leading "#" because gitlab returns it but github wants the color without it
769+
description: label.description,
768770
};
769771

770772
await utils.sleep(this.delayInMs);

src/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ import * as fs from 'fs';
1616

1717
import AWS from 'aws-sdk';
1818

19+
const CCERROR = '\x1b[31m%s\x1b[0m'; // red
20+
const CCWARN = '\x1b[33m%s\x1b[0m'; // yellow
21+
const CCINFO = '\x1b[36m%s\x1b[0m'; // cyan
22+
const CCSUCCESS = '\x1b[32m%s\x1b[0m'; // green
23+
1924
const counters = {
2025
nrOfPlaceholderIssues: 0,
2126
nrOfReplacementIssues: 0,
@@ -331,6 +336,9 @@ async function transferMilestones(usePlaceholders: boolean) {
331336
*/
332337
async function transferLabels(attachmentLabel = true, useLowerCase = true) {
333338
inform('Transferring Labels');
339+
console.warn(CCWARN,'NOTE (2022): GitHub descriptions are limited to 100 characters, and do not accept 4-byte Unicode');
340+
341+
const invalidUnicode = /[\u{10000}-\u{10FFFF}]|(?![*#0-9]+)[\p{Emoji}\p{Emoji_Modifier}\p{Emoji_Component}\p{Emoji_Modifier_Base}\p{Emoji_Presentation}]/gu;
334342

335343
// Get a list of all labels associated with this project
336344
let labels: SimpleLabel[] = await gitlabApi.Labels.all(
@@ -345,13 +353,15 @@ async function transferLabels(attachmentLabel = true, useLowerCase = true) {
345353
const hasAttachmentLabel = {
346354
name: 'has attachment',
347355
color: '#fbca04',
356+
description: 'Attachment was not transfered from GitLab',
348357
};
349358
labels.push(hasAttachmentLabel);
350359
}
351360

352361
const gitlabMergeRequestLabel = {
353362
name: 'gitlab merge request',
354363
color: '#b36b00',
364+
description: '',
355365
};
356366
labels.push(gitlabMergeRequestLabel);
357367

@@ -362,6 +372,28 @@ async function transferLabels(attachmentLabel = true, useLowerCase = true) {
362372

363373
if (!githubLabels.find(l => l === label.name)) {
364374
console.log('Creating: ' + label.name);
375+
376+
if (label.description) {
377+
if (label.description.match(invalidUnicode)) {
378+
console.warn(CCWARN,`⚠️ Removed invalid unicode characters from description.`);
379+
const cleanedDescription = label.description.replace(invalidUnicode, '').trim();
380+
console.debug(` "${label.description}"\n\t to\n "${cleanedDescription}"`);
381+
label.description = cleanedDescription;
382+
}
383+
if (label.description.length > 100) {
384+
const trimmedDescription = label.description.slice(0,100).trim();
385+
if (settings.trimOversizedLabelDescriptions) {
386+
console.warn(CCWARN,`⚠️ Description too long (${label.description.length}), it was trimmed:`);
387+
console.debug(` "${label.description}"\n\t to\n "${trimmedDescription}"`);
388+
label.description = trimmedDescription;
389+
} else {
390+
console.warn(CCWARN,`⚠️ Description too long (${label.description.length}), it was excluded.`);
391+
console.debug(` "${label.description}"`);
392+
label.description = '';
393+
}
394+
}
395+
}
396+
365397
try {
366398
// process asynchronous code in sequence
367399
await githubHelper.createLabel(label).catch(x => {});

src/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default interface Settings {
2525
useReplacementIssuesForCreationFails: boolean;
2626
useIssuesForAllMergeRequests: boolean;
2727
filterByLabel?: string;
28+
trimOversizedLabelDescriptions: boolean;
2829
skipMergeRequestStates: string[];
2930
skipMatchingComments: string[];
3031
mergeRequests: {

0 commit comments

Comments
 (0)