Edits history of script submission #3696 for ' Get projects paginated (jira)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Jira = {
      username: string;
      password: string;
      domain: string;
    };
    /**
     * Get projects paginated
     * Returns a [paginated](#pagination) list of projects visible to the user.
     */
    export async function main(
      auth: Jira,
      startAt: string | undefined,
      maxResults: string | undefined,
      orderBy:
        | "category"
        | "-category"
        | "+category"
        | "key"
        | "-key"
        | "+key"
        | "name"
        | "-name"
        | "+name"
        | "owner"
        | "-owner"
        | "+owner"
        | "issueCount"
        | "-issueCount"
        | "+issueCount"
        | "lastIssueUpdatedDate"
        | "-lastIssueUpdatedDate"
        | "+lastIssueUpdatedDate"
        | "archivedDate"
        | "+archivedDate"
        | "-archivedDate"
        | "deletedDate"
        | "+deletedDate"
        | "-deletedDate"
        | undefined,
      id: string | undefined,
      keys: string | undefined,
      query: string | undefined,
      typeKey: string | undefined,
      categoryId: string | undefined,
      action: "view" | "browse" | "edit" | "create" | undefined,
      expand: string | undefined,
      status: string | undefined,
      properties: string | undefined,
      propertyQuery: string | undefined
    ) {
      const url = new URL(
        `https://${auth.domain}.atlassian.net/rest/api/2/project/search`
      );
      for (const [k, v] of [
        ["startAt", startAt],
        ["maxResults", maxResults],
        ["orderBy", orderBy],
        ["id", id],
        ["keys", keys],
        ["query", query],
        ["typeKey", typeKey],
        ["categoryId", categoryId],
        ["action", action],
        ["expand", expand],
        ["status", status],
        ["properties", properties],
        ["propertyQuery", propertyQuery],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      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 396 days ago

  • nativets
    type Jira = {
      username: string;
      password: string;
      domain: string;
    };
    /**
     * Get projects paginated
     * Returns a [paginated](#pagination) list of projects visible to the user.
     */
    export async function main(
      auth: Jira,
      startAt: string | undefined,
      maxResults: string | undefined,
      orderBy:
        | "category"
        | "-category"
        | "+category"
        | "key"
        | "-key"
        | "+key"
        | "name"
        | "-name"
        | "+name"
        | "owner"
        | "-owner"
        | "+owner"
        | "issueCount"
        | "-issueCount"
        | "+issueCount"
        | "lastIssueUpdatedDate"
        | "-lastIssueUpdatedDate"
        | "+lastIssueUpdatedDate"
        | "archivedDate"
        | "+archivedDate"
        | "-archivedDate"
        | "deletedDate"
        | "+deletedDate"
        | "-deletedDate"
        | undefined,
      id: string | undefined,
      keys: string | undefined,
      query: string | undefined,
      typeKey: string | undefined,
      categoryId: string | undefined,
      action: "view" | "browse" | "edit" | "create" | undefined,
      expand: string | undefined,
      status: string | undefined,
      properties: string | undefined,
      propertyQuery: string | undefined
    ) {
      const url = new URL(
        `https://${auth.domain}.atlassian.net/rest/api/2/project/search`
      );
      for (const [k, v] of [
        ["startAt", startAt],
        ["maxResults", maxResults],
        ["orderBy", orderBy],
        ["id", id],
        ["keys", keys],
        ["query", query],
        ["typeKey", typeKey],
        ["categoryId", categoryId],
        ["action", action],
        ["expand", expand],
        ["status", status],
        ["properties", properties],
        ["propertyQuery", propertyQuery],
      ]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      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 948 days ago