Skip to content

Commit

Permalink
chore: migrate to remeda v2 (+regen bun.lockb)
Browse files Browse the repository at this point in the history
  • Loading branch information
karl-run committed Aug 16, 2024
1 parent 63ade8e commit 371ae34
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 26 deletions.
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion src/actions/builds/builds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export async function checkBuilds(rerunFailed: boolean): Promise<void> {

const { SUCCESS, FAILURE, CANCELLED, BUILDING, ...rest } = reposByState

log(`Found ${R.pipe(reposByState, R.toPairs, R.flatMap(R.last), R.length)} repos with build status`)
log(`Found ${R.pipe(reposByState, R.entries(), R.flatMap(R.last), R.length)} repos with build status`)
log(chalk.green(` Success: ${SUCCESS?.length ?? 0} repos`))
log(chalk.yellow(` Bulding: ${BUILDING?.length ?? 0} repos`))
for (const repo of BUILDING ?? []) {
Expand Down
2 changes: 1 addition & 1 deletion src/actions/prs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export async function openPrs(includeDrafts: boolean, noBot: boolean): Promise<v

R.pipe(
openPrs,
R.toPairs,
R.entries(),
R.sortBy([([, prs]) => R.first(prs)?.updatedAt ?? '', 'desc']),
R.forEach(([repo, prs]) => {
log(chalk.greenBright(repo))
Expand Down
4 changes: 2 additions & 2 deletions src/actions/repo-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ const reposQuery = /* GraphQL */ `
${BaseRepoNodeFragment}
`

async function getMainBranchPerRepo(team: string): Promise<[string, string][]> {
async function getMainBranchPerRepo(team: string): Promise<(readonly [string, string])[]> {
log(chalk.green(`Getting all main branch for repos in team ${team}`))

const queryResult = await ghGqlQuery<OrgTeamRepoResult<unknown>>(reposQuery, { team })

return R.pipe(
queryResult.organization.team.repositories.nodes,
removeIgnoredAndArchived,
R.map((repo) => [repo.name, repo.defaultBranchRef.name]),
R.map((repo) => [repo.name, repo.defaultBranchRef.name] as const),
)
}

Expand Down
8 changes: 4 additions & 4 deletions src/actions/repo-settings/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export async function syncRepoSettings(): Promise<void> {
try {
await applySettings(team, repo.name)
log(chalk.green(' OK!'))
} catch (e) {
log(chalk.red(' FAILED! :('))
} catch (error) {
log(chalk.red(` FAILED! :( (why: ${error})`))
}
}

Expand All @@ -44,7 +44,7 @@ export async function syncRepoSettings(): Promise<void> {

const expectedRepoSettingsPairs: [string, unknown][] = R.pipe(
EXPECTED_REPO_SETTINGS,
R.toPairs,
R.entries(),
R.sortBy(([key]) => key),
)

Expand All @@ -66,7 +66,7 @@ export async function checkSettingsOK(team: string, repo: string): Promise<[stri
'has_projects',
'has_wiki',
]),
R.toPairs,
R.entries(),
R.sortBy(([key]) => key),
)

Expand Down
2 changes: 1 addition & 1 deletion src/actions/repos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function getRepos(): Promise<void> {
removeIgnoredAndArchived,
R.groupBy((it) => it.primaryLanguage?.name ?? 'unknown'),
R.mapValues(R.sortBy([(it) => it.pushedAt, 'asc'])),
R.toPairs,
R.entries(),
R.sortBy(([, [firstNode]]) => firstNode.pushedAt),
)

Expand Down
6 changes: 4 additions & 2 deletions src/actions/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const availablePages = {
}

type PageKeys = (typeof pageKeys)[number]
const pageKeys = R.keys.strict(staticPages)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const pageKeys = R.keys(staticPages)

const availableApps = {
sykmeldinger: {
Expand Down Expand Up @@ -71,7 +72,8 @@ const availableApps = {
}

type AppKeys = (typeof appKeys)[number]
const appKeys = R.keys.strict(availableApps)
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const appKeys = R.keys(availableApps)

export async function openResource(what: string | null, env: string | null): Promise<void> {
if (what != null && isPage(what)) {
Expand Down
4 changes: 2 additions & 2 deletions src/analytics/analytics-global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export async function showUsageAnalytics(detailed: boolean): Promise<void> {
log(`Analytics of ${chalk.blueBright('tsm')} usage for ${chalk.greenBright(user)}:`)
R.pipe(
usage,
R.toPairs,
R.entries(),
R.sortBy([([, value]) => value.usage, 'desc']),
R.filter(([, value]) => value.usage > 1),
R.take(10),
R.forEach(([key, value]) => {
log(` ${chalk.blueBright(key)}: ${chalk.green(value.usage)}`)
R.pipe(
value.argsUsage,
R.toPairs,
R.entries(),
R.filter(([, value]) => value > 1),
R.forEach(([key, value]) => {
if (detailed) {
Expand Down
12 changes: 6 additions & 6 deletions src/analytics/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export function usageDiff(command: Command[], args?: Args): Usage {
usage: 1,
argsUsage: R.pipe(
args ?? ({} satisfies Args),
R.toPairs.strict,
R.entries(),
R.map(([key, value]) => `${key}:${value}`),
R.map((key): [string, number] => [key, 1]),
R.fromPairs.strict,
R.fromEntries(),
),
},
}
Expand All @@ -25,7 +25,7 @@ export function applyDiff(usage: Usage, existing: UserCommandUsage): UserCommand
...existing.usage,
...R.pipe(
usage,
R.toPairs.strict,
R.entries(),
R.map(([commandKey, value]): [string, CommandUsage] => [
commandKey,
{
Expand All @@ -34,17 +34,17 @@ export function applyDiff(usage: Usage, existing: UserCommandUsage): UserCommand
...existing.usage[commandKey]?.argsUsage,
...R.pipe(
value.argsUsage,
R.toPairs.strict,
R.entries(),
R.map(([key, value]): [string, number] => [
key,
value + (existing.usage[commandKey]?.argsUsage[key] ?? 0),
]),
R.fromPairs.strict,
R.fromEntries(),
),
},
},
]),
R.fromPairs.strict,
R.fromEntries(),
),
},
}
Expand Down
17 changes: 11 additions & 6 deletions src/common/kubectl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ export async function changeContext(namespace: string, cluster: 'dev-gcp' | 'pro
const clusterOutput = await $`kubectl config use-context ${cluster}`.quiet()
const namespaceOutput = await $`kubectl config set-context --current --namespace=${namespace}`.quiet()

clusterOutput.exitCode === 0
? log(`→ Cluster set to ${chalk.green(cluster)}`)
: log(chalk.red(`Failed to set cluster: ${clusterOutput.stderr.toString()}`))
namespaceOutput.exitCode === 0
? log(`→ Namespace set to ${chalk.green(namespace)}`)
: log(chalk.red(`Failed to set namespace: ${namespaceOutput.stderr.toString()}`))
if (clusterOutput.exitCode === 0) {
log(`→ Cluster set to ${chalk.green(cluster)}`)
} else {
log(chalk.red(`Failed to set cluster: ${clusterOutput.stderr.toString()}`))
}

if (namespaceOutput.exitCode === 0) {
log(`→ Namespace set to ${chalk.green(namespace)}`)
} else {
log(chalk.red(`Failed to set namespace: ${namespaceOutput.stderr.toString()}`))
}
}
2 changes: 1 addition & 1 deletion src/common/octokit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export type OrgTeamRepoResult<AdditionalRepoProps> = OrgTeamResult<{

export const removeIgnoredAndArchived: <AdditionalRepoProps>(
nodes: BaseRepoNode<AdditionalRepoProps>[],
) => BaseRepoNode<AdditionalRepoProps>[] = R.createPipe(
) => BaseRepoNode<AdditionalRepoProps>[] = R.piped(
R.filter((it) => !it.isArchived),
R.filter(blacklisted),
)

0 comments on commit 371ae34

Please sign in to comment.