Edits history of script submission #1628 for ' Test the push repository webhook (github)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Github = {
      token: string;
    };
    /**
     * Test the push repository webhook
     * This will trigger the hook with the latest push to the current repository if the hook is subscribed to `push` events. If the hook is not subscribed to `push` events, the server will respond with 204 but no test POST will be generated.
    
    **Note**: Previously `/repos/:owner/:repo/hooks/:hook_id/test`
     */
    export async function main(
      auth: Github,
      owner: string,
      repo: string,
      hook_id: string
    ) {
      const url = new URL(
        `https://api.github.com/repos/${owner}/${repo}/hooks/${hook_id}/tests`
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 367 days ago

  • nativets
    type Github = {
      token: string;
    };
    /**
     * Test the push repository webhook
     * This will trigger the hook with the latest push to the current repository if the hook is subscribed to `push` events. If the hook is not subscribed to `push` events, the server will respond with 204 but no test POST will be generated.
    
    **Note**: Previously `/repos/:owner/:repo/hooks/:hook_id/test`
     */
    export async function main(
      auth: Github,
      owner: string,
      repo: string,
      hook_id: string
    ) {
      const url = new URL(
        `https://api.github.com/repos/${owner}/${repo}/hooks/${hook_id}/tests`
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 927 days ago