Edits history of script submission #1463 for ' Create or update an annotation (bitbucket)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Create or update an annotation
     * Creates or updates an individual annotation for the specified report.
     */
    export async function main(
      auth: Bitbucket,
      workspace: string,
      repo_slug: string,
      commit: string,
      reportId: string,
      annotationId: 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/${annotationId}`
      );
    
      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

  • nativets
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Create or update an annotation
     * Creates or updates an individual annotation for the specified report.
     */
    export async function main(
      auth: Bitbucket,
      workspace: string,
      repo_slug: string,
      commit: string,
      reportId: string,
      annotationId: 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/${annotationId}`
      );
    
      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

  • nativets
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Create or update an annotation
     * Creates or updates an individual annotation for the specified report.
    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.
    
    Just as reports, annotation needs to be uploaded with a unique ID that 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). 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.
    
    ### Sample cURL request:
    ```
    curl --request PUT 'https://api.bitbucket.org/2.0/repositories/<username>/<reposity-name>/commit/<commit-hash>/reports/mySystem-001/annotations/mysystem-annotation001' \
    --header 'Content-Type: application/json' \
    --data-raw '{
        "title": "Security scan report",
        "annotation_type": "VULNERABILITY",
        "summary": "This line represents a security thread.",
        "severity": "HIGH",
        "path": "my-service/src/main/java/com/myCompany/mysystem/logic/Main.java",
        "line": 42
    }'
    ```
    
    ### 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,
      annotationId: 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/${annotationId}`
      );
    
      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