Edits history of script submission #1446 for ' Create a schedule (bitbucket)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Create a schedule
     * Create a schedule for the given repository.
     */
    export async function main(
      auth: Bitbucket,
      workspace: string,
      repo_slug: string,
      body: { type: string; [k: string]: unknown } & {
        target: {
          selector: { type: string; [k: string]: unknown } & {
            type?: "branches" | "tags" | "bookmarks" | "default" | "custom";
            pattern?: string;
            [k: string]: unknown;
          };
          ref_name: string;
          ref_type: "branch";
          [k: string]: unknown;
        };
        enabled?: boolean;
        cron_pattern: string;
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/pipelines_config/schedules`
      );
    
      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 schedule
     * Create a schedule for the given repository.
     */
    export async function main(
      auth: Bitbucket,
      workspace: string,
      repo_slug: string,
      body: { type: string; [k: string]: unknown } & {
        target: {
          selector: { type: string; [k: string]: unknown } & {
            type?: "branches" | "tags" | "bookmarks" | "default" | "custom";
            pattern?: string;
            [k: string]: unknown;
          };
          ref_name: string;
          ref_type: "branch";
          [k: string]: unknown;
        };
        enabled?: boolean;
        cron_pattern: string;
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/pipelines_config/schedules`
      );
    
      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 935 days ago