type Bitbucket = {
username: string;
password: string;
};
/**
* Bulk create or update annotations
* Bulk upload of annotations.
*/
export async function main(
auth: Bitbucket,
workspace: string,
repo_slug: string,
commit: string,
reportId: string,
body: ({ type: string; [k: string]: unknown } & {
external_id?: string;
uuid?: string;
annotation_type?: "VULNERABILITY" | "CODE_SMELL" | "BUG";
path?: string;
line?: number;
summary?: string;
details?: string;
result?: "PASSED" | "FAILED" | "SKIPPED" | "IGNORED";
severity?: "CRITICAL" | "HIGH" | "MEDIUM" | "LOW";
link?: string;
created_on?: string;
updated_on?: string;
[k: string]: unknown;
})[]
) {
const url = new URL(
`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/commit/${commit}/reports/${reportId}/annotations`
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
},
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 297 days ago
type Bitbucket = {
username: string;
password: string;
};
/**
* Bulk create or update annotations
* Bulk upload of annotations.
*/
export async function main(
auth: Bitbucket,
workspace: string,
repo_slug: string,
commit: string,
reportId: string,
body: [
{ type: string; [k: string]: unknown } & {
external_id?: string;
uuid?: string;
annotation_type?: "VULNERABILITY" | "CODE_SMELL" | "BUG";
path?: string;
line?: number;
summary?: string;
details?: string;
result?: "PASSED" | "FAILED" | "SKIPPED" | "IGNORED";
severity?: "CRITICAL" | "HIGH" | "MEDIUM" | "LOW";
link?: string;
created_on?: string;
updated_on?: string;
[k: string]: unknown;
},
...({ type: string; [k: string]: unknown } & {
external_id?: string;
uuid?: string;
annotation_type?: "VULNERABILITY" | "CODE_SMELL" | "BUG";
path?: string;
line?: number;
summary?: string;
details?: string;
result?: "PASSED" | "FAILED" | "SKIPPED" | "IGNORED";
severity?: "CRITICAL" | "HIGH" | "MEDIUM" | "LOW";
link?: string;
created_on?: string;
updated_on?: string;
[k: string]: unknown;
})[]
]
) {
const url = new URL(
`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/commit/${commit}/reports/${reportId}/annotations`
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
},
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 346 days ago
type Bitbucket = {
username: string;
password: string;
};
/**
* Bulk create or update annotations
* Bulk upload of annotations.
*/
export async function main(
auth: Bitbucket,
workspace: string,
repo_slug: string,
commit: string,
reportId: string,
body: [
{ type: string; [k: string]: unknown } & {
external_id?: string;
uuid?: string;
annotation_type?: "VULNERABILITY" | "CODE_SMELL" | "BUG";
path?: string;
line?: number;
summary?: string;
details?: string;
result?: "PASSED" | "FAILED" | "SKIPPED" | "IGNORED";
severity?: "CRITICAL" | "HIGH" | "MEDIUM" | "LOW";
link?: string;
created_on?: string;
updated_on?: string;
[k: string]: unknown;
},
...({ type: string; [k: string]: unknown } & {
external_id?: string;
uuid?: string;
annotation_type?: "VULNERABILITY" | "CODE_SMELL" | "BUG";
path?: string;
line?: number;
summary?: string;
details?: string;
result?: "PASSED" | "FAILED" | "SKIPPED" | "IGNORED";
severity?: "CRITICAL" | "HIGH" | "MEDIUM" | "LOW";
link?: string;
created_on?: string;
updated_on?: string;
[k: string]: unknown;
})[],
]
) {
const url = new URL(
`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/commit/${commit}/reports/${reportId}/annotations`
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
},
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 352 days ago
type Bitbucket = {
username: string;
password: string;
};
/**
* Bulk create or update annotations
* Bulk upload of annotations.
Annotations are individual findings that have been identified as part of a report, for example, a line of code that represents a vulnerability. These annotations can be attached to a specific file and even a specific line in that file, however, that is optional. Annotations are not mandatory and a report can contain up to 1000 annotations.
Add the annotations you want to upload as objects in a JSON array and make sure each annotation has the external_id field set to a unique value. If you want to use an existing id from your own system, we recommend prefixing it with your system's name to avoid collisions, for example, mySystem-annotation001. The external id can later be used to identify the report as an alternative to the generated [UUID](https://developer.atlassian.com/bitbucket/api/2/reference/meta/uri-uuid#uuid). You can upload up to 100 annotations per POST request.
### Sample cURL request:
```
curl --location 'https://api.bitbucket.org/2.0/repositories/<username>/<reposity-name>/commit/<commit-hash>/reports/mysystem-001/annotations' \
--header 'Content-Type: application/json' \
--data-raw '[
{
"external_id": "mysystem-annotation001",
"title": "Security scan report",
"annotation_type": "VULNERABILITY",
"summary": "This line represents a security threat.",
"severity": "HIGH",
"path": "my-service/src/main/java/com/myCompany/mysystem/logic/Main.java",
"line": 42
},
{
"external_id": "mySystem-annotation002",
"title": "Bug report",
"annotation_type": "BUG",
"result": "FAILED",
"summary": "This line might introduce a bug.",
"severity": "MEDIUM",
"path": "my-service/src/main/java/com/myCompany/mysystem/logic/Helper.java",
"line": 13
}
]'
```
### Possible field values:
annotation_type: VULNERABILITY, CODE_SMELL, BUG
result: PASSED, FAILED, IGNORED, SKIPPED
severity: HIGH, MEDIUM, LOW, CRITICAL
Please refer to the [Code Insights documentation](https://confluence.atlassian.com/bitbucket/code-insights-994316785.html) for more information.
*/
export async function main(
auth: Bitbucket,
workspace: string,
repo_slug: string,
commit: string,
reportId: string,
body: [
{ type: string; [k: string]: unknown } & {
external_id?: string;
uuid?: string;
annotation_type?: "VULNERABILITY" | "CODE_SMELL" | "BUG";
path?: string;
line?: number;
summary?: string;
details?: string;
result?: "PASSED" | "FAILED" | "SKIPPED" | "IGNORED";
severity?: "CRITICAL" | "HIGH" | "MEDIUM" | "LOW";
link?: string;
created_on?: string;
updated_on?: string;
[k: string]: unknown;
},
...({ type: string; [k: string]: unknown } & {
external_id?: string;
uuid?: string;
annotation_type?: "VULNERABILITY" | "CODE_SMELL" | "BUG";
path?: string;
line?: number;
summary?: string;
details?: string;
result?: "PASSED" | "FAILED" | "SKIPPED" | "IGNORED";
severity?: "CRITICAL" | "HIGH" | "MEDIUM" | "LOW";
link?: string;
created_on?: string;
updated_on?: string;
[k: string]: unknown;
})[],
]
) {
const url = new URL(
`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/commit/${commit}/reports/${reportId}/annotations`
);
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
},
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 352 days ago