Edits history of script submission #1338 for ' Create a webhook for a workspace (bitbucket)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Create a webhook for a workspace
     * Creates a new webhook on the specified workspace.
     */
    export async function main(auth: Bitbucket, workspace: string) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/workspaces/${workspace}/hooks`
      );
    
      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.json();
    }
    

    Submitted by hugo697 375 days ago

  • nativets
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Create a webhook for a workspace
     * Creates a new webhook on the specified workspace.
     */
    export async function main(auth: Bitbucket, workspace: string) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/workspaces/${workspace}/hooks`
      );
    
      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.json();
    }
    

    Submitted by hugo697 935 days ago

  • nativets
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Create a webhook for a workspace
     * Creates a new webhook on the specified workspace.
    
    Workspace webhooks are fired for events from all repositories contained
    by that workspace.
    
    Example:
    
    ```
    $ curl -X POST -u credentials -H 'Content-Type: application/json'
      https://api.bitbucket.org/2.0/workspaces/my-workspace/hooks
      -d '
        {
          "description": "Webhook Description",
          "url": "https://example.com/",
          "active": true,
          "secret": "this is a really bad secret",
          "events": [
            "repo:push",
            "issue:created",
            "issue:updated"
          ]
        }'
    ```
    
    When the `secret` is provided it will be used as the key to generate a HMAC
    digest value sent in the `X-Hub-Signature` header at delivery time. Passing
    a `null` or empty `secret` or not passing a `secret` will leave the webhook's
    secret unset. Bitbucket only generates the `X-Hub-Signature` when the webhook's
    secret is set.
    
    This call requires the webhook scope, as well as any scope
    that applies to the events that the webhook subscribes to. In the
    example above that means: `webhook`, `repository` and `issue`.
    
    The `url` must properly resolve and cannot be an internal, non-routed address.
    
    Only workspace owners can install webhooks on workspaces.
     */
    export async function main(auth: Bitbucket, workspace: string) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/workspaces/${workspace}/hooks`
      );
    
      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.json();
    }
    

    Submitted by hugo697 935 days ago