Edits history of script submission #1283 for ' Get a branch (bitbucket)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Get a branch
     * Returns a branch object within the specified repository.
    
    This call requires authentication. Private repositories require the
    caller to authenticate with an account that has appropriate
    authorization.
    
    For Git, the branch name should not include any prefixes (e.g.
    refs/heads).
     */
    export async function main(
      auth: Bitbucket,
      name: string,
      repo_slug: string,
      workspace: string
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/refs/branches/${name}`
      );
    
      const response = await fetch(url, {
        method: "GET",
        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.json();
    }
    

    Submitted by hugo697 375 days ago

  • nativets
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Get a branch
     * Returns a branch object within the specified repository.
    
    This call requires authentication. Private repositories require the
    caller to authenticate with an account that has appropriate
    authorization.
    
    For Git, the branch name should not include any prefixes (e.g.
    refs/heads).
     */
    export async function main(
      auth: Bitbucket,
      name: string,
      repo_slug: string,
      workspace: string
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/refs/branches/${name}`
      );
    
      const response = await fetch(url, {
        method: "GET",
        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.json();
    }
    

    Submitted by hugo697 935 days ago