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
5 changes: 5 additions & 0 deletions .changeset/sour-garlics-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ghui': patch
---

Migrate to effect-atom/atom-react
46 changes: 23 additions & 23 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@
"private": true,
"devDependencies": {
"@changesets/cli": "^2.29.8",
"@effect/language-service": "^0.62.1",
"@effect/language-service": "^0.62.3",
"@ianvs/prettier-plugin-sort-imports": "^4.7.0",
"@macklinu/prettier-config": "^0.1.0",
"@types/bun": "1.3.4",
"@types/react": "^19.2.7",
"husky": "^9.1.7",
"lint-staged": "^16.2.7",
"oxlint": "^1.32.0",
"oxlint": "^1.33.0",
"prettier": "^3.7.4"
},
"peerDependencies": {
"typescript": "^5.9.3"
},
"dependencies": {
"@effect-atom/atom-react": "^0.4.4",
"@effect/cli": "^0.72.1",
"@effect/platform": "^0.93.6",
"@effect/platform": "^0.93.8",
"@effect/platform-bun": "^0.86.0",
"@opentui/core": "^0.1.60",
"@opentui/react": "^0.1.60",
"@tanstack/react-query": "^5.90.12",
"cli-spinners": "^3.3.0",
"effect": "^3.19.11",
"react": "^19.2.1",
"effect": "^3.19.12",
"react": "^19.2.3",
"tiny-invariant": "^1.3.3",
"zustand": "^5.0.9"
},
Expand Down
76 changes: 55 additions & 21 deletions src/GitHub.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Atom } from '@effect-atom/atom-react'
import * as BunContext from '@effect/platform-bun/BunContext'
import * as Command from '@effect/platform/Command'
import { pipe } from 'effect'
import * as Data from 'effect/Data'
import * as Duration from 'effect/Duration'
import * as Effect from 'effect/Effect'
import * as Option from 'effect/Option'
import * as Schema from 'effect/Schema'
Expand Down Expand Up @@ -50,13 +52,7 @@ const runCommand = Effect.fn(function* (command: Command.Command) {
export class PullRequests extends Effect.Service<PullRequests>()('ghui/GitHub/PullRequests', {
accessors: true,
sync: () => ({
list: Effect.fn('PullRequests.list')(function* ({
author,
repo,
}: {
author: Option.Option<string>
repo: Option.Option<string>
}) {
list: Effect.fn('PullRequests.list')(function* ({ repo }: { repo: Option.Option<string> }) {
const args = yield* CommandArgs.builder()
.append(
'gh',
Expand All @@ -71,18 +67,27 @@ export class PullRequests extends Effect.Service<PullRequests>()('ghui/GitHub/Pu

const result = yield* CommandArgs.toCommand(args).pipe(Command.string)

const response = yield* Schema.decodeUnknown(
return yield* Schema.decodeUnknown(
Schema.compose(Schema.parseJson(), Schema.Array(GitHubApiSchema.PullRequest))
)(result)

return Option.match(author, {
onSome: (author) => response.filter((pr) => pr.user.login === author),
onNone: () => response,
})
}),
}),
dependencies: [BunContext.layer],
}) {}
}) {
static readonly runtime = Atom.runtime(PullRequests.Default)

static readonly listAtom = Atom.family((repo: Option.Option<string>) =>
PullRequests.runtime
.atom(PullRequests.list({ repo }).pipe(Effect.provide(BunContext.layer)))
.pipe(Atom.setIdleTTL(Duration.decode('10 minutes')))
)
}

type UpdateBranchOptions = {
number: number
repo: string
type?: 'rebase' | 'merge'
}

export class PullRequest extends Effect.Service<PullRequest>()('ghui/GitHub/PullRequest', {
accessors: true,
Expand All @@ -108,11 +113,7 @@ export class PullRequest extends Effect.Service<PullRequest>()('ghui/GitHub/Pull
number,
repo,
type = 'merge',
}: {
number: number
repo: string
type?: 'rebase' | 'merge'
}) {
}: UpdateBranchOptions) {
const args = yield* CommandArgs.builder()
.append('gh', 'pr', 'update-branch', number, '--repo', repo)
.appendIf(type === 'rebase', () => '--rebase')
Expand All @@ -132,7 +133,32 @@ export class PullRequest extends Effect.Service<PullRequest>()('ghui/GitHub/Pull
}),
}),
dependencies: [BunContext.layer],
}) {}
}) {
static readonly runtime = Atom.runtime(PullRequest.Default)

static readonly markdownDescriptionAtom = Atom.family((number: Option.Option<number>) =>
PullRequest.runtime
.atom(
Effect.gen(function* () {
if (Option.isNone(number)) {
return Option.none<string>()
}
const description = yield* PullRequest.markdownDescription({ number: number.value })
if (!description) {
return Option.none<string>()
}
return Option.some(description)
}).pipe(Effect.provide(BunContext.layer))
)
.pipe(Atom.setIdleTTL(Duration.decode('30 minutes')))
)

static readonly updateBranchAtom = PullRequest.runtime.fn(
Effect.fnUntraced(function* (args: UpdateBranchOptions) {
return yield* PullRequest.updateBranch(args)
}, Effect.provide(BunContext.layer))
)
}

export class Issues extends Effect.Service<Issues>()('ghui/GitHub/Issues', {
accessors: true,
Expand Down Expand Up @@ -160,4 +186,12 @@ export class Issues extends Effect.Service<Issues>()('ghui/GitHub/Issues', {
}),
dependencies: [BunContext.layer],
}),
}) {}
}) {
static readonly runtime = Atom.runtime(Issues.Default)

static readonly listAtom = Atom.family((repo: Option.Option<string>) =>
Issues.runtime
.atom(Issues.list({ repo }).pipe(Effect.provide(BunContext.layer)))
.pipe(Atom.setIdleTTL(Duration.decode('10 minutes')))
)
}
Loading