Edits history of script submission #1587 for ' Create a commit by uploading a file (bitbucket)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Create a commit by uploading a file
     * This endpoint is used to create new commits in the repository by
    uploading files.
     */
    export async function main(
      auth: Bitbucket,
      repo_slug: string,
      workspace: string,
      message: string | undefined,
      author: string | undefined,
      parents: string | undefined,
      files: string | undefined,
      branch: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/src`
      );
      for (const [k, v] of [
        ["message", message],
        ["author", author],
        ["parents", parents],
        ["files", files],
        ["branch", branch],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 375 days ago

  • nativets
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Create a commit by uploading a file
     * This endpoint is used to create new commits in the repository by
    uploading files.
     */
    export async function main(
      auth: Bitbucket,
      repo_slug: string,
      workspace: string,
      message: string | undefined,
      author: string | undefined,
      parents: string | undefined,
      files: string | undefined,
      branch: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/src`
      );
      for (const [k, v] of [
        ["message", message],
        ["author", author],
        ["parents", parents],
        ["files", files],
        ["branch", branch],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 935 days ago