Edits history of script submission #3513 for ' Add comment (jira)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Jira = {
      username: string;
      password: string;
      domain: string;
    };
    /**
     * Add comment
     * Adds a comment to an issue.
    
    This operation can be accessed anonymously.
    
    **[Permissions](#permissions) required:**
    
     *  *Browse projects* and *Add comments* [ project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue containing the comment 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,
      expand: string | undefined,
      body: {
        author?: {
          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;
        };
        body?: string;
        created?: string;
        id?: string;
        jsdAuthorCanSeeRequest?: boolean;
        jsdPublic?: boolean;
        properties?: { key?: string; value?: { [k: string]: unknown } }[];
        renderedBody?: string;
        self?: string;
        updateAuthor?: {
          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;
        };
        updated?: string;
        visibility?: {
          identifier?: string;
          type?: "group" | "role";
          value?: string;
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://${auth.domain}.atlassian.net/rest/api/2/issue/${issueIdOrKey}/comment`
      );
      for (const [k, v] of [["expand", expand]]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      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;
    };
    /**
     * Add comment
     * Adds a comment to an issue.
    
    This operation can be accessed anonymously.
    
    **[Permissions](#permissions) required:**
    
     *  *Browse projects* and *Add comments* [ project permission](https://confluence.atlassian.com/x/yodKLg) for the project that the issue containing the comment 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,
      expand: string | undefined,
      body: {
        author?: {
          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;
        };
        body?: string;
        created?: string;
        id?: string;
        jsdAuthorCanSeeRequest?: boolean;
        jsdPublic?: boolean;
        properties?: { key?: string; value?: { [k: string]: unknown } }[];
        renderedBody?: string;
        self?: string;
        updateAuthor?: {
          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;
        };
        updated?: string;
        visibility?: {
          identifier?: string;
          type?: "group" | "role";
          value?: string;
          [k: string]: unknown;
        };
        [k: string]: unknown;
      }
    ) {
      const url = new URL(
        `https://${auth.domain}.atlassian.net/rest/api/2/issue/${issueIdOrKey}/comment`
      );
      for (const [k, v] of [["expand", expand]]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      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