Edits history of script submission #3420 for ' Send notification for issue (jira)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Jira = {
      username: string;
      password: string;
      domain: string;
    };
    /**
     * Send notification for issue
     * Creates an email notification for an issue and adds it to the mail queue.
    
    **[Permissions](#permissions) required:**
    
     *  *Browse Projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue is in.
     *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.
     */
    export async function main(
      auth: Jira,
      issueIdOrKey: string,
      body: {
        htmlBody?: string;
        restrict?: {
          groupIds?: string[];
          groups?: { groupId?: string; name?: string; self?: string }[];
          permissions?: { id?: string; key?: string; [k: string]: unknown }[];
        };
        subject?: string;
        textBody?: string;
        to?: {
          assignee?: boolean;
          groupIds?: string[];
          groups?: { groupId?: string; name?: string; self?: string }[];
          reporter?: boolean;
          users?: {
            accountId?: string;
            accountType?: string;
            active?: boolean;
            avatarUrls?: {
              "16x16"?: string;
              "24x24"?: string;
              "32x32"?: string;
              "48x48"?: string;
            };
            displayName?: string;
            emailAddress?: string;
            key?: string;
            name?: string;
            self?: string;
            timeZone?: string;
          }[];
          voters?: boolean;
          watchers?: boolean;
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://${auth.domain}.atlassian.net/rest/api/2/issue/${issueIdOrKey}/notify`
      );
    
      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 396 days ago

  • nativets
    type Jira = {
      username: string;
      password: string;
      domain: string;
    };
    /**
     * Send notification for issue
     * Creates an email notification for an issue and adds it to the mail queue.
    
    **[Permissions](#permissions) required:**
    
     *  *Browse Projects* [project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue is in.
     *  If [issue-level security](https://confluence.atlassian.com/x/J4lKLg) is configured, issue-level security permission to view the issue.
     */
    export async function main(
      auth: Jira,
      issueIdOrKey: string,
      body: {
        htmlBody?: string;
        restrict?: {
          groupIds?: string[];
          groups?: { groupId?: string; name?: string; self?: string }[];
          permissions?: { id?: string; key?: string; [k: string]: unknown }[];
        };
        subject?: string;
        textBody?: string;
        to?: {
          assignee?: boolean;
          groupIds?: string[];
          groups?: { groupId?: string; name?: string; self?: string }[];
          reporter?: boolean;
          users?: {
            accountId?: string;
            accountType?: string;
            active?: boolean;
            avatarUrls?: {
              "16x16"?: string;
              "24x24"?: string;
              "32x32"?: string;
              "48x48"?: string;
            };
            displayName?: string;
            emailAddress?: string;
            key?: string;
            name?: string;
            self?: string;
            timeZone?: string;
          }[];
          voters?: boolean;
          watchers?: boolean;
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://${auth.domain}.atlassian.net/rest/api/2/issue/${issueIdOrKey}/notify`
      );
    
      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 948 days ago