Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions sample_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default {
useReplacementIssuesForCreationFails: true,
useIssuesForAllMergeRequests: false,
filterByLabel: null,
trimOversizedLabelDescriptions: false,
skipMergeRequestStates: [],
skipMatchingComments: [],
mergeRequests: {
Expand Down
2 changes: 2 additions & 0 deletions src/githubHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export interface MilestoneImport {
export interface SimpleLabel {
name: string;
color: string;
description: string;
}

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

await utils.sleep(this.delayInMs);
Expand Down
32 changes: 32 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ import * as fs from 'fs';

import AWS from 'aws-sdk';

const CCERROR = '\x1b[31m%s\x1b[0m'; // red
const CCWARN = '\x1b[33m%s\x1b[0m'; // yellow
const CCINFO = '\x1b[36m%s\x1b[0m'; // cyan
const CCSUCCESS = '\x1b[32m%s\x1b[0m'; // green

const counters = {
nrOfPlaceholderIssues: 0,
nrOfReplacementIssues: 0,
Expand Down Expand Up @@ -326,6 +331,9 @@ async function transferMilestones(usePlaceholders: boolean) {
*/
async function transferLabels(attachmentLabel = true, useLowerCase = true) {
inform('Transferring Labels');
console.warn(CCWARN,'NOTE (2022): GitHub descriptions are limited to 100 characters, and do not accept 4-byte Unicode');

const invalidUnicode = /[\u{10000}-\u{10FFFF}]|(?![*#0-9]+)[\p{Emoji}\p{Emoji_Modifier}\p{Emoji_Component}\p{Emoji_Modifier_Base}\p{Emoji_Presentation}]/gu;

// Get a list of all labels associated with this project
let labels: SimpleLabel[] = await gitlabApi.Labels.all(
Expand All @@ -340,13 +348,15 @@ async function transferLabels(attachmentLabel = true, useLowerCase = true) {
const hasAttachmentLabel = {
name: 'has attachment',
color: '#fbca04',
description: 'Attachment was not transfered from GitLab',
};
labels.push(hasAttachmentLabel);
}

const gitlabMergeRequestLabel = {
name: 'gitlab merge request',
color: '#b36b00',
description: '',
};
labels.push(gitlabMergeRequestLabel);

Expand All @@ -357,6 +367,28 @@ async function transferLabels(attachmentLabel = true, useLowerCase = true) {

if (!githubLabels.find(l => l === label.name)) {
console.log('Creating: ' + label.name);

if (label.description) {
if (label.description.match(invalidUnicode)) {
console.warn(CCWARN,`⚠️ Removed invalid unicode characters from description.`);
const cleanedDescription = label.description.replace(invalidUnicode, '').trim();
console.debug(` "${label.description}"\n\t to\n "${cleanedDescription}"`);
label.description = cleanedDescription;
}
if (label.description.length > 100) {
const trimmedDescription = label.description.slice(0,100).trim();
if (settings.trimOversizedLabelDescriptions) {
console.warn(CCWARN,`⚠️ Description too long (${label.description.length}), it was trimmed:`);
console.debug(` "${label.description}"\n\t to\n "${trimmedDescription}"`);
label.description = trimmedDescription;
} else {
console.warn(CCWARN,`⚠️ Description too long (${label.description.length}), it was excluded.`);
console.debug(` "${label.description}"`);
label.description = '';
}
}
}

try {
// process asynchronous code in sequence
await githubHelper.createLabel(label).catch(x => {});
Expand Down
1 change: 1 addition & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default interface Settings {
useReplacementIssuesForCreationFails: boolean;
useIssuesForAllMergeRequests: boolean;
filterByLabel?: string;
trimOversizedLabelDescriptions: boolean;
skipMergeRequestStates: string[];
skipMatchingComments: string[];
mergeRequests: {
Expand Down