Skip to content

Commit

Permalink
Merge pull request #12 from AirWalk-Digital/feature-refactor
Browse files Browse the repository at this point in the history
feat: edit and new pr
  • Loading branch information
PAYNEA03 committed Jan 4, 2024
2 parents bae6361 + 4d51339 commit 3352fbc
Show file tree
Hide file tree
Showing 11 changed files with 508 additions and 219 deletions.
37 changes: 37 additions & 0 deletions components/appbar/ControlBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { NewContentDialog, NewBranchDialog } from "@/components/appbar";
import * as matter from "gray-matter";
import { toSnakeCase } from "@/lib/utils/stringUtils";
import { useRouter } from "next/navigation";
import { raisePR } from "@/lib/github";

export function ControlBar({
open: controlBarOpen,
Expand Down Expand Up @@ -129,6 +130,7 @@ export function ControlBar({
const url = new URL(window.location.href);
const params = new URLSearchParams(url.search);
params.set("branch", newBranch.name);
params.set("edit", "true");
url.search = params.toString();
window.location.href = url.toString();
}
Expand Down Expand Up @@ -183,6 +185,40 @@ export function ControlBar({
setIsAddOpen(false);
};

const handlePR = async () => {
const prName = (branch) => {
const [branchType, ...titleParts] = branch.split("/");
const title = titleParts.join(" ").replace(/([a-z])([A-Z])/g, "$1 $2");
return `${
branchType.charAt(0).toUpperCase() + branchType.slice(1)
}: ${title
.split("-")
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(" ")}`;
};
console.debug(
"ControlBar:handlePR: ",
context.owner,
context.repo,
prName(context.branch),
"PR created from Airview",
context.branch,
collection.branch
);
try {
await raisePR(
context.owner,
context.repo,
prName(context.branch),
"PR created from Airview",
context.branch,
collection.branch
);
} catch (e) {
throw new Error(`Error creating PR: ${e.message}`);
}
};

return (
<>
<ControlBarComponent
Expand All @@ -200,6 +236,7 @@ export function ControlBar({
editMode={editMode}
fetchBranches={fetchBranches}
handleNewBranch={onNewBranchClicked}
handlePR={handlePR}
/>
<NewContentDialog dialogOpen={isAddOpen} handleDialog={handleAdd} />
<NewBranchDialog
Expand Down
Loading

0 comments on commit 3352fbc

Please sign in to comment.