Edits history of script submission #5920 for ' Create a task on a pull request (bitbucket)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Create a task on a pull request
     * Creates a new pull request task.
    
    Returns the newly created pull request task.
    
    Tasks can optionally be created in relation to a comment specified by the comment's ID which
    will cause the task to appear below the comment on a pull request when viewed in Bitbucket.
     */
    export async function main(
      auth: Bitbucket,
      pull_request_id: string,
      repo_slug: string,
      workspace: string,
      body: {
        content: { raw: string };
        comment?: { type: string; [k: string]: unknown } & {
          id?: number;
          created_on?: string;
          updated_on?: string;
          content?: {
            raw?: string;
            markup?: "markdown" | "creole" | "plaintext";
            html?: string;
          };
          user?: { type: string; [k: string]: unknown } & {
            links?: {
              avatar?: { href?: string; name?: string };
              [k: string]: unknown;
            };
            created_on?: string;
            display_name?: string;
            username?: string;
            uuid?: string;
            [k: string]: unknown;
          };
          deleted?: boolean;
          parent?: unknown;
          inline?: { from?: number; to?: number; path: string };
          links?: {
            self?: { href?: string; name?: string };
            html?: { href?: string; name?: string };
            code?: { href?: string; name?: string };
          };
          [k: string]: unknown;
        };
        pending?: boolean;
      }
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/pullrequests/${pull_request_id}/tasks`
      );
    
      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 375 days ago

  • nativets
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Create a task on a pull request
     * Creates a new pull request task.
    
    Returns the newly created pull request task.
    
    Tasks can optionally be created in relation to a comment specified by the comment's ID which
    will cause the task to appear below the comment on a pull request when viewed in Bitbucket.
     */
    export async function main(
      auth: Bitbucket,
      pull_request_id: string,
      repo_slug: string,
      workspace: string,
      body: {
        content: { raw: string };
        comment?: { type: string; [k: string]: unknown } & {
          id?: number;
          created_on?: string;
          updated_on?: string;
          content?: {
            raw?: string;
            markup?: "markdown" | "creole" | "plaintext";
            html?: string;
          };
          user?: { type: string; [k: string]: unknown } & {
            links?: {
              avatar?: { href?: string; name?: string };
              [k: string]: unknown;
            };
            created_on?: string;
            display_name?: string;
            username?: string;
            uuid?: string;
            [k: string]: unknown;
          };
          deleted?: boolean;
          parent?: unknown;
          inline?: { from?: number; to?: number; path: string };
          links?: {
            self?: { href?: string; name?: string };
            html?: { href?: string; name?: string };
            code?: { href?: string; name?: string };
          };
          [k: string]: unknown;
        };
        pending?: boolean;
      }
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/pullrequests/${pull_request_id}/tasks`
      );
    
      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 802 days ago