Skip to content

Commit

Permalink
Separate into a new method and split interfaces into another file
Browse files Browse the repository at this point in the history
  • Loading branch information
bordoni committed Feb 22, 2024
1 parent efffb13 commit ca5d4c5
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 77 deletions.
67 changes: 67 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@

interface ProjectNodeIDResponse {
organization?: {
projectV2: {
id: string
}
}

user?: {
projectV2: {
id: string
}
}
}

interface OwnerResponse {
user?: {
id: string
}
organization?: {
id: string
}
}

interface ProjectNode {
node: {
id: string
title: string
number: number
}
}

interface ProjectsEdgesNodesResponse {
organization?: {
projectsV2: {
totalCount: number
edges: ProjectNode[]
}
}

user?: {
projectsV2: {
totalCount: number
edges: ProjectNode[]
}
}
}

interface ProjectAddItemResponse {
addProjectV2ItemById: {
item: {
id: string
project: {
id: string
url: string
}
}
}
}

interface ProjectCopyTemplateResponse {
copyProjectV2: {
projectV2: {
id: string
}
}
}
96 changes: 19 additions & 77 deletions src/project-link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,27 @@ import * as core from '@actions/core'
import * as github from '@actions/github'
import {minimatch} from 'minimatch'

const projectUrlParse = /\/(?<ownerType>orgs|users)\/(?<ownerName>[^/]+)\/projects\/(?<projectNumber>\d+)/

interface ProjectNodeIDResponse {
organization?: {
projectV2: {
id: string
}
}

user?: {
projectV2: {
id: string
}
}
}

interface OwnerResponse {
user?: {
id: string
}
organization?: {
id: string
}
}
// Local imports.
import './interfaces'

interface ProjectNode {
node: {
id: string
title: string
number: number
}
}

interface ProjectsEdgesNodesResponse {
organization?: {
projectsV2: {
totalCount: number
edges: ProjectNode[]
}
}
const projectUrlParse = /\/(?<ownerType>orgs|users)\/(?<ownerName>[^/]+)\/projects\/(?<projectNumber>\d+)/

user?: {
projectsV2: {
totalCount: number
edges: ProjectNode[]
}
export const parseProjectName = (baseBranch: string, prefixRemove?: string, sufixRemove?: string, replaceWithSpaces?: string): string => {
let projectName = baseBranch
if (prefixRemove) {
projectName = projectName.replace(new RegExp(`^${prefixRemove}`, 'i'), '')
}
}

interface ProjectAddItemResponse {
addProjectV2ItemById: {
item: {
id: string
project: {
id: string
url: string
}
}
if (sufixRemove) {
projectName = projectName.replace(new RegExp(`${sufixRemove}$`, 'i'), '')
}
}

interface ProjectCopyTemplateResponse {
copyProjectV2: {
projectV2: {
id: string
if (replaceWithSpaces) {
for (const charToReplace of replaceWithSpaces.split('')) {
projectName = projectName.replace(new RegExp(charToReplace, 'g'), ' ')
}
}
return projectName
}

export async function projectLink(): Promise<void> {
Expand All @@ -93,24 +47,12 @@ export async function projectLink(): Promise<void> {
}
}

let projectName = baseBranch
const prefixRemove = core.getInput('name-prefix-remove')
const sufixRemove = core.getInput('name-sufix-remove')
const replaceWithSpaces = core.getInput('name-replace-with-spaces')

if (prefixRemove) {
projectName = projectName.replace(new RegExp(`^${prefixRemove}`, 'i'), '')
}

if (sufixRemove) {
projectName = projectName.replace(new RegExp(`${sufixRemove}$`, 'i'), '')
}

if (replaceWithSpaces) {
for (const charToReplace of replaceWithSpaces.split('')) {
projectName = projectName.replace(new RegExp(charToReplace, 'g'), ' ')
}
}
const projectName = parseProjectName(
baseBranch,
core.getInput('prefix-remove'),
core.getInput('sufix-remove'),
core.getInput('replace-with-spaces')
)

const labeled =
core
Expand Down

0 comments on commit ca5d4c5

Please sign in to comment.