diff --git a/README.md b/README.md index 1180039..5953bfd 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,18 @@ We need github repository url, github api token 1. **Repository URL**: GitHub repository full url. 2. **Github API Key**: GitHub API Key +### Target Branch Selection + +By default, PRs are created against the `main` branch. To target a different branch, include the branch path in the repository URL: + +| URL Format | Target Branch | +| -------------------------------------------------- | ---------------- | +| `https://github.com/owner/repo` | `main` (default) | +| `https://github.com/owner/repo/tree/develop` | `develop` | +| `https://github.com/owner/repo/tree/feature/icons` | `feature/icons` | + +Simply paste the URL from your browser when viewing the target branch on GitHub. + API Key need `repo`, `workflow` scope. ![repo-scope](./images/repo-scope.png) diff --git a/figma-plugin/common/fromUi.ts b/figma-plugin/common/fromUi.ts index 30b3996..70b2a66 100644 --- a/figma-plugin/common/fromUi.ts +++ b/figma-plugin/common/fromUi.ts @@ -7,6 +7,7 @@ interface GithubData { owner: string; name: string; apiKey: string; + branch: string; } interface IconaMetaData { diff --git a/figma-plugin/common/types.ts b/figma-plugin/common/types.ts index 5cd6b9b..da37815 100644 --- a/figma-plugin/common/types.ts +++ b/figma-plugin/common/types.ts @@ -2,6 +2,7 @@ export interface GithubData { owner: string; name: string; apiKey: string; + branch: string; } export interface ExportOptions { diff --git a/figma-plugin/plugin-src/github.ts b/figma-plugin/plugin-src/github.ts index 7bcb341..91c5a0c 100644 --- a/figma-plugin/plugin-src/github.ts +++ b/figma-plugin/plugin-src/github.ts @@ -193,8 +193,7 @@ export function createGithubClient( return response.json(); } - async function createSettingPR() { - const baseBranch = "main"; + async function createSettingPR(baseBranch = "main") { const newBranch = `icona-setting-${new Date().getTime()}`; const commitTitle = "chore: add icona.yml"; @@ -244,8 +243,8 @@ export function createGithubClient( async function createDeployPR( svgs: Record, iconaFileName?: string, + baseBranch = "main", ) { - const baseBranch = "main"; const newBranch = `icona-update-${new Date().getTime()}`; const fileName = iconaFileName || "icons"; diff --git a/figma-plugin/plugin-src/listeners.ts b/figma-plugin/plugin-src/listeners.ts index f5b33d2..9cbbc93 100644 --- a/figma-plugin/plugin-src/listeners.ts +++ b/figma-plugin/plugin-src/listeners.ts @@ -8,7 +8,7 @@ import { getIconaFrame, setLocalData } from "./utils.js"; export function listenDeployIcon() { on("DEPLOY_ICON", async ({ githubData, icons, options }) => { try { - const { owner, name, apiKey } = githubData; + const { owner, name, apiKey, branch } = githubData; const { fileName, png } = options; const { createDeployPR } = createGithubClient(owner, name, apiKey); @@ -25,7 +25,7 @@ export function listenDeployIcon() { const iconaData = await exportFromIconaIconData(assetFrames, icons, png); - await createDeployPR(iconaData, fileName); + await createDeployPR(iconaData, fileName, branch); emit("DEPLOY_DONE", null); figma.notify("Icons deployed", { timeout: 5000 }); diff --git a/figma-plugin/ui-src/contexts/AppContext.tsx b/figma-plugin/ui-src/contexts/AppContext.tsx index 91ce943..b3e02b8 100644 --- a/figma-plugin/ui-src/contexts/AppContext.tsx +++ b/figma-plugin/ui-src/contexts/AppContext.tsx @@ -195,6 +195,7 @@ export function AppProvider({ children }: { children: React.ReactNode }) { owner: "", name: "", apiKey: "", + branch: "main", }, iconPreview: {}, diff --git a/figma-plugin/ui-src/utils/string.ts b/figma-plugin/ui-src/utils/string.ts index 93bf7eb..ebd463d 100644 --- a/figma-plugin/ui-src/utils/string.ts +++ b/figma-plugin/ui-src/utils/string.ts @@ -7,13 +7,15 @@ export const getFigmaFileKeyFromUrl = (fileUrl: string) => { }; export const getGithubDataFromUrl = (githubUrl: string) => { - const match = githubUrl.match(/github\.com\/([^/]+)\/([^/]+)/); + // Match: github.com/{owner}/{repo} or github.com/{owner}/{repo}/tree/{branch} + const match = githubUrl.match( + /github\.com\/([^/]+)\/([^/]+)(?:\/tree\/(.+))?/, + ); if (match) { return { owner: match[1], name: match[2], - // NOTE: This is not used currently - // repo: `${match[1]}/${match[2]}`, + branch: match[3] || "main", // default to "main" if no branch specified }; } return null;