Skip to content
Open
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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions figma-plugin/common/fromUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface GithubData {
owner: string;
name: string;
apiKey: string;
branch: string;
}

interface IconaMetaData {
Expand Down
1 change: 1 addition & 0 deletions figma-plugin/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface GithubData {
owner: string;
name: string;
apiKey: string;
branch: string;
}

export interface ExportOptions {
Expand Down
5 changes: 2 additions & 3 deletions figma-plugin/plugin-src/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -244,8 +243,8 @@ export function createGithubClient(
async function createDeployPR(
svgs: Record<string, IconaIconData>,
iconaFileName?: string,
baseBranch = "main",
) {
const baseBranch = "main";
const newBranch = `icona-update-${new Date().getTime()}`;

const fileName = iconaFileName || "icons";
Expand Down
4 changes: 2 additions & 2 deletions figma-plugin/plugin-src/listeners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 });
Expand Down
1 change: 1 addition & 0 deletions figma-plugin/ui-src/contexts/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export function AppProvider({ children }: { children: React.ReactNode }) {
owner: "",
name: "",
apiKey: "",
branch: "main",
},
iconPreview: {},

Expand Down
8 changes: 5 additions & 3 deletions figma-plugin/ui-src/utils/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down