type Bitbucket = {
username: string;
password: string;
};
/**
* Create or update a report
* Creates or updates a report for the specified commit.
*/
export async function main(
auth: Bitbucket,
workspace: string,
repo_slug: string,
commit: string,
reportId: string,
body: { type: string; [k: string]: unknown } & {
uuid?: string;
title?: string;
details?: string;
external_id?: string;
reporter?: string;
link?: string;
remote_link_enabled?: boolean;
logo_url?: string;
report_type?: "SECURITY" | "COVERAGE" | "TEST" | "BUG";
result?: "PASSED" | "FAILED" | "PENDING";
data?: {
type?:
| "BOOLEAN"
| "DATE"
| "DURATION"
| "LINK"
| "NUMBER"
| "PERCENTAGE"
| "TEXT";
title?: string;
value?: { [k: string]: unknown };
[k: string]: unknown;
}[];
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}`
);
const response = await fetch(url, {
method: "PUT",
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 375 days ago
type Bitbucket = {
username: string;
password: string;
};
/**
* Create or update a report
* Creates or updates a report for the specified commit.
*/
export async function main(
auth: Bitbucket,
workspace: string,
repo_slug: string,
commit: string,
reportId: string,
body: { type: string; [k: string]: unknown } & {
uuid?: string;
title?: string;
details?: string;
external_id?: string;
reporter?: string;
link?: string;
remote_link_enabled?: boolean;
logo_url?: string;
report_type?: "SECURITY" | "COVERAGE" | "TEST" | "BUG";
result?: "PASSED" | "FAILED" | "PENDING";
data?: {
type?:
| "BOOLEAN"
| "DATE"
| "DURATION"
| "LINK"
| "NUMBER"
| "PERCENTAGE"
| "TEXT";
title?: string;
value?: { [k: string]: unknown };
[k: string]: unknown;
}[];
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}`
);
const response = await fetch(url, {
method: "PUT",
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 935 days ago
type Bitbucket = {
username: string;
password: string;
};
/**
* Create or update a report
* Creates or updates a report for the specified commit.
To upload a report, make sure to generate an ID that is unique across all reports for that commit. 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-001.
### Sample cURL request:
```
curl --request PUT 'https://api.bitbucket.org/2.0/repositories/<username>/<reposity-name>/commit/<commit-hash>/reports/mysystem-001' \
--header 'Content-Type: application/json' \
--data-raw '{
"title": "Security scan report",
"details": "This pull request introduces 10 new dependency vulnerabilities.",
"report_type": "SECURITY",
"reporter": "mySystem",
"link": "http://www.mysystem.com/reports/001",
"result": "FAILED",
"data": [
{
"title": "Duration (seconds)",
"type": "DURATION",
"value": 14
},
{
"title": "Safe to merge?",
"type": "BOOLEAN",
"value": false
}
]
}'
```
### Possible field values:
report_type: SECURITY, COVERAGE, TEST, BUG
result: PASSED, FAILED, PENDING
data.type: BOOLEAN, DATE, DURATION, LINK, NUMBER, PERCENTAGE, TEXT
#### Data field formats
| Type Field | Value Field Type | Value Field Display |
|:--------------|:------------------|:--------------------|
| None/ Omitted | Number, String or Boolean (not an array or object) | Plain text |
| BOOLEAN | Boolean | The value will be read as a JSON boolean and displayed as 'Yes' or 'No'. |
| DATE | Number | The value will be read as a JSON number in the form of a Unix timestamp (milliseconds) and will be displayed as a relative date if the date is less than one week ago, otherwise it will be displayed as an absolute date. |
| DURATION | Number | The value will be read as a JSON number in milliseconds and will be displayed in a human readable duration format. |
| LINK | Object: `{"text": "Link text here", "href": "https://link.to.annotation/in/external/tool"}` | The value will be read as a JSON object containing the fields "text" and "href" and will be displayed as a clickable link on the report. |
| NUMBER | Number | The value will be read as a JSON number and large numbers will be displayed in a human readable format (e.g. 14.3k). |
| PERCENTAGE | Number (between 0 and 100) | The value will be read as a JSON number between 0 and 100 and will be displayed with a percentage sign. |
| TEXT | String | The value will be read as a JSON string and will be displayed as-is |
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 } & {
uuid?: string;
title?: string;
details?: string;
external_id?: string;
reporter?: string;
link?: string;
remote_link_enabled?: boolean;
logo_url?: string;
report_type?: "SECURITY" | "COVERAGE" | "TEST" | "BUG";
result?: "PASSED" | "FAILED" | "PENDING";
data?: {
type?:
| "BOOLEAN"
| "DATE"
| "DURATION"
| "LINK"
| "NUMBER"
| "PERCENTAGE"
| "TEXT";
title?: string;
value?: { [k: string]: unknown };
[k: string]: unknown;
}[];
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}`
);
const response = await fetch(url, {
method: "PUT",
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 935 days ago