Skip to content

Commit

Permalink
add PRs to create page dropdown, update git to checkout prs (#11)
Browse files Browse the repository at this point in the history
* add PRs to create page dropdown, update git to checkout prs

* better naming for requestParams to github api calls

* remove BranchType, unused and unneccesary
  • Loading branch information
eriktaubeneck authored Apr 3, 2024
1 parent 7e08a8e commit 8b52733
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 3 deletions.
2 changes: 1 addition & 1 deletion server/app/query/create/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function IPAForm({
>
<PassedStateSelectMenu
id="branch"
label="Branch"
label="Branch / PR"
options={branchNames}
selected={selectedBranchName}
setSelected={setSelectedBranchName}
Expand Down
30 changes: 28 additions & 2 deletions server/app/query/github.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function Branches(
repo: string,
bypassCache: boolean,
): Promise<Branch[]> {
const requestParams: any = {
const branchesRequestParams: any = {
owner: owner,
repo: repo,
per_page: 100,
Expand All @@ -35,7 +35,7 @@ export async function Branches(
};
const branchesIter = octokit.paginate.iterator(
octokit.rest.repos.listBranches,
requestParams,
branchesRequestParams,
);

let branchesArray: Branch[] = [];
Expand All @@ -47,6 +47,32 @@ export async function Branches(
});
}
}

const pullsRequestParams: any = {
owner: owner,
repo: repo,
state: "open",
per_page: 100,
request: {
cache: bypassCache ? "reload" : "default",
},
timestamp: new Date().getTime(),
};

const pullRequestsIter = octokit.paginate.iterator(
octokit.rest.pulls.list,
pullsRequestParams,
);

for await (const { data: pullRequests } of pullRequestsIter) {
for (const pullRequest of pullRequests) {
branchesArray.push({
name: `#${pullRequest.number}: ${pullRequest.title}`,
commitHash: pullRequest.head.sha.substring(0, 7),
});
}
}

const mainBranchIndex = branchesArray.findIndex(
(branch) => branch.name === "main",
);
Expand Down
9 changes: 9 additions & 0 deletions server/app/query/view/[id]/components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ export function LogViewer({
{log.logLine}
</div>
))}
<div
key="last"
className={clsx(
"text-slate-900 dark:text-slate-100 text-xs whitespace-pre-line animate-pulse",
sourceCodePro.className,
)}
>
{">_"}
</div>
</div>
</div>
);
Expand Down
21 changes: 21 additions & 0 deletions sidecar/app/query/ipa.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ def pre_run(self):
self.skip = True


@dataclass(kw_only=True)
class IPAUpdateRemoteOriginStep(LoggerOutputCommandStep):
repo_path: Path
status: ClassVar[Status] = Status.STARTING

@classmethod
def build_from_query(cls, query: IPAQuery):
return cls(
repo_path=query.paths.repo_path,
logger=query.logger,
)

def build_command(self) -> LoggerOutputCommand:
return LoggerOutputCommand(
cmd=f"git -C {self.repo_path} config --add remote.origin.fetch "
"'+refs/pull/*/head:refs/remotes/origin/pr/*'",
logger=self.logger,
)


@dataclass(kw_only=True)
class IPAFetchUpstreamStep(LoggerOutputCommandStep):
repo_path: Path
Expand Down Expand Up @@ -388,6 +408,7 @@ class IPAHelperQuery(IPAQuery):

step_classes: ClassVar[list[type[Step]]] = [
IPACloneStep,
IPAUpdateRemoteOriginStep,
IPAFetchUpstreamStep,
IPACheckoutCommitStep,
IPAHelperCompileStep,
Expand Down

0 comments on commit 8b52733

Please sign in to comment.