Skip to content

Commit

Permalink
fix: color format
Browse files Browse the repository at this point in the history
  • Loading branch information
risenforces committed Jun 26, 2021
1 parent 932096b commit a1599c4
Showing 1 changed file with 34 additions and 15 deletions.
49 changes: 34 additions & 15 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { getInput, getBooleanInput, setFailed } from '@actions/core';
import { context, getOctokit } from '@actions/github';
import { Issue, LinearClient, LinearFetch, Team, User, WorkflowState, IssueLabel } from '@linear/sdk';
import {
Issue,
LinearClient,
LinearFetch,
Team,
User,
WorkflowState,
IssueLabel,
} from '@linear/sdk';
import { WebhookPayload } from '@actions/github/lib/interfaces';

const linearToken = getInput('linear-token', { required: true });
Expand Down Expand Up @@ -111,15 +119,15 @@ async function githubSyncLabels({ linearIssues, pr }: { linearIssues: Issue[]; p
}
}

const linearActualLabels = Array.from(linearActualLabelsMap.values())
const linearActualLabels = Array.from(linearActualLabelsMap.values());

const toAdd: AbstractLabel[] = [];
const toAddMissing: AbstractLabel[] = [];
const toRemove: AbstractLabel[] = [];

const byName = (label: AbstractLabel) => (another: AbstractLabel) => {
return label.name === another.name
}
return label.name === another.name;
};

if (shouldAddLabels) {
for (const requiredLabel of linearActualLabels) {
Expand Down Expand Up @@ -184,7 +192,7 @@ async function repoLabelsCreate(labels: AbstractLabel[]) {
owner: context.repo.owner,
repo: context.repo.repo,
name: label.name,
color: label.color,
color: ColorFormat.github(label.color),
}),
),
);
Expand All @@ -195,7 +203,7 @@ async function prLabelsAdd(pr: PR, labels: AbstractLabel[]) {
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr.number,
labels: labels.map(label => label.name)
labels: labels.map((label) => label.name),
});
}

Expand All @@ -212,17 +220,20 @@ async function prLabelsRemove(pr: PR, labels: AbstractLabel[]) {
);
}

function prStatusMapToLinear(prStatus: PullState): string {
const state = stateMap.find(({ pullState }) => pullState === prStatus);
if (!state) {
throw new Error(`Not found linear state for "${prStatus}"`);
}
return state.linearStateName;
}
const ColorFormat = {
linear: (string: string) => {
if (string.startsWith('#')) return string.toUpperCase();
return '#' + string.toUpperCase();
},
github: (string: string) => {
if (!string.startsWith('#')) return string.toLowerCase();
return string.slice(1).toLowerCase();
},
};

interface AbstractLabel {
name?: string
color?: string
name?: string;
color?: string;
}

interface Label {
Expand All @@ -245,6 +256,14 @@ interface PR {
labels: Label[];
}

function prStatusMapToLinear(prStatus: PullState): string {
const state = stateMap.find(({ pullState }) => pullState === prStatus);
if (!state) {
throw new Error(`Not found linear state for "${prStatus}"`);
}
return state.linearStateName;
}

function prStatusDetect(pr: PR): PullState {
if (prIsDrafted(pr)) return 'drafted';
if (prIsReady(pr)) return 'ready';
Expand Down

0 comments on commit a1599c4

Please sign in to comment.