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
4 changes: 3 additions & 1 deletion src/dcc-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,9 @@ async function push(args: { title?: string; submit?: boolean }) {
if (currentPr) {
await githubOps.updatePrTitle(currentPr.number, args.title)
} else {
await githubOps.createPr(args.title)
const prNumber = await githubOps.createPr(args.title)
await gitOps.renameBranch(String(prNumber))
print(`Local branch renamed to ${prNumber}`)
}

if (!args.submit) {
Expand Down
3 changes: 2 additions & 1 deletion src/dcc-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export const DccConfig = z.object({
openOn: z.enum(['github', 'graphite']).optional(),
})

export type DccConfig = z.infer<typeof DccConfig> // eslint-disable-line no-redeclare
// eslint-disable-next-line no-redeclare
export type DccConfig = z.infer<typeof DccConfig>
18 changes: 18 additions & 0 deletions src/git-ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ export class GitOps {
return bs.branches[bs.current]
}

async getRemoteBranchName(): Promise<string | undefined> {
try {
const out = await this.git.raw(['rev-parse', '--abbrev-ref', '@{upstream}'])
// origin/my-branch -> my-branch
return out.trim().replace(/^[^/]+\//, '')
} catch {
return undefined
}
}

async noUncommittedChanges(): Promise<void> {
const d = await this.git.diffSummary()
if (d.files.length) {
Expand Down Expand Up @@ -219,6 +229,14 @@ export class GitOps {
await this.git.raw(['commit', '-m', message])
}

async renameBranch(newName: string): Promise<void> {
const remoteBranch = await this.getRemoteBranchName()
await this.git.branch(['-m', newName])
if (remoteBranch) {
await this.git.branch(['--set-upstream-to', `origin/${remoteBranch}`])
}
}

async deleteBranch(branchName: string): Promise<void> {
await this.git.branch(['-D', branchName])
}
Expand Down
4 changes: 3 additions & 1 deletion src/github-ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class GithubOps {
const b = await this.gitOps.getRepo()
await this.kit.pulls.update({ owner: b.owner, repo: b.name, pull_number: prNumber, title: newTitle })
}
async createPr(title: string): Promise<void> {
async createPr(title: string): Promise<number> {
const b = await this.gitOps.getBranch()
const r = await this.gitOps.getRepo()

Expand Down Expand Up @@ -104,5 +104,7 @@ export class GithubOps {
issue_number: issueNumber,
labels: this.prLabels,
})

return issueNumber
}
}
4 changes: 4 additions & 0 deletions src/gql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ export class GraphqlOps {
}

async getCurrentPr(): Promise<CurrentPrInfo | undefined> {
const remoteBranch = await this.gitOps.getRemoteBranchName()
if (remoteBranch) {
return this.getPrOfBranch(remoteBranch)
}
const b = await this.gitOps.getBranch()
return this.getPrOfBranch(b.name)
}
Expand Down