type Github = {
token: string;
};
/**
* Create a tree
* The tree creation API accepts nested entries.
*/
export async function main(
auth: Github,
owner: string,
repo: string,
body: {
base_tree?: string;
tree: {
content?: string;
mode?: "100644" | "100755" | "040000" | "160000" | "120000";
path?: string;
sha?: string;
type?: "blob" | "tree" | "commit";
[k: string]: unknown;
}[];
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.github.com/repos/${owner}/${repo}/git/trees`
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 367 days ago
type Github = {
token: string;
};
/**
* Create a tree
* The tree creation API accepts nested entries.
*/
export async function main(
auth: Github,
owner: string,
repo: string,
body: {
base_tree?: string;
tree: {
content?: string;
mode?: "100644" | "100755" | "040000" | "160000" | "120000";
path?: string;
sha?: string;
type?: "blob" | "tree" | "commit";
[k: string]: unknown;
}[];
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.github.com/repos/${owner}/${repo}/git/trees`
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 927 days ago