type Github = {
token: string;
};
/**
* Create or update file contents
* Creates a new file or replaces an existing file in a repository. You must authenticate using an access token with the `workflow` scope to use this endpoint.
**Note:** If you use this endpoint and the "[Delete a file](https://docs.github.com/rest/reference/repos/#delete-file)" endpoint in parallel, the concurrent requests will conflict and you will receive errors. You must use these endpoints serially instead.
*/
export async function main(
auth: Github,
owner: string,
repo: string,
path: string,
body: {
author?: {
date?: string;
email: string;
name: string;
[k: string]: unknown;
};
branch?: string;
committer?: {
date?: string;
email: string;
name: string;
[k: string]: unknown;
};
content: string;
message: string;
sha?: string;
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.github.com/repos/${owner}/${repo}/contents/${path}`
);
const response = await fetch(url, {
method: "PUT",
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 or update file contents
* Creates a new file or replaces an existing file in a repository. You must authenticate using an access token with the `workflow` scope to use this endpoint.
**Note:** If you use this endpoint and the "[Delete a file](https://docs.github.com/rest/reference/repos/#delete-file)" endpoint in parallel, the concurrent requests will conflict and you will receive errors. You must use these endpoints serially instead.
*/
export async function main(
auth: Github,
owner: string,
repo: string,
path: string,
body: {
author?: {
date?: string;
email: string;
name: string;
[k: string]: unknown;
};
branch?: string;
committer?: {
date?: string;
email: string;
name: string;
[k: string]: unknown;
};
content: string;
message: string;
sha?: string;
[k: string]: unknown;
}
) {
const url = new URL(
`https://api.github.com/repos/${owner}/${repo}/contents/${path}`
);
const response = await fetch(url, {
method: "PUT",
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