type Github = {
token: string;
};
/**
* Create a snapshot of dependencies for a repository
* Create a new snapshot of a repository's dependencies. You must authenticate using an access token with the `repo` scope to use this endpoint for a repository that the requesting user has access to.
*/
export async function main(
auth: Github,
owner: string,
repo: string,
body: {
detector: { name: string; url: string; version: string };
job: { correlator: string; html_url?: string; id: string };
manifests?: {
[k: string]: {
file?: { source_location?: string };
metadata?: { [k: string]: string | number | boolean };
name: string;
resolved?: {
[k: string]: {
dependencies?: string[];
metadata?: { [k: string]: string | number | boolean };
package_url?: string;
relationship?: "direct" | "indirect";
scope?: "runtime" | "development";
};
};
};
};
metadata?: { [k: string]: string | number | boolean };
ref: string;
scanned: string;
sha: string;
version: number;
}
) {
const url = new URL(
`https://api.github.com/repos/${owner}/${repo}/dependency-graph/snapshots`
);
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 snapshot of dependencies for a repository
* Create a new snapshot of a repository's dependencies. You must authenticate using an access token with the `repo` scope to use this endpoint for a repository that the requesting user has access to.
*/
export async function main(
auth: Github,
owner: string,
repo: string,
body: {
detector: { name: string; url: string; version: string };
job: { correlator: string; html_url?: string; id: string };
manifests?: {
[k: string]: {
file?: { source_location?: string };
metadata?: { [k: string]: string | number | boolean };
name: string;
resolved?: {
[k: string]: {
dependencies?: string[];
metadata?: { [k: string]: string | number | boolean };
package_url?: string;
relationship?: "direct" | "indirect";
scope?: "runtime" | "development";
};
};
};
};
metadata?: { [k: string]: string | number | boolean };
ref: string;
scanned: string;
sha: string;
version: number;
}
) {
const url = new URL(
`https://api.github.com/repos/${owner}/${repo}/dependency-graph/snapshots`
);
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