@gitkraken/provider-apis 0.12.1 → 0.12.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.12.3
4
+
5
+ - added `getPullRequestsForUser` (BitBucket)
6
+ - fixed error on `setIssueStatus` success if using `window.fetch` (Jira)
7
+
8
+ ## 0.12.2
9
+
10
+ - added `EXAMPLES.md` file which contains snippets that demonstrate how to use each function in the library. this document is a work in progress and will be updated as time goes on
11
+ - added `oid` field to `baseRef` and `headRef` fields in `GitPullRequest` (Azure, BitBucket, GitHub, GitLab)
12
+ - fixed error on `setIssueStatus` success (Jira)
13
+ - fixed emails not working as filter values for `getIssuesForProject` (Jira)
14
+ - fixed names with spaces not working as a value for `mentionLogin` filter for `getIssuesForProject` (Jira)
15
+
3
16
  ## 0.12.1
4
17
 
5
18
  - added `getPullRequestsForUser` (GitLab)
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var Ze=Object.create;var K=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var et=Object.getOwnPropertyNames;var tt=Object.getPrototypeOf,rt=Object.prototype.hasOwnProperty;var G=(e,r)=>{for(var t in r)K(e,t,{get:r[t],enumerable:!0})},xe=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of et(r))!rt.call(e,n)&&n!==t&&K(e,n,{get:()=>r[n],enumerable:!(s=Ye(r,n))||s.enumerable});return e};var st=(e,r,t)=>(t=e!=null?Ze(tt(e)):{},xe(r||!e||!e.__esModule?K(t,"default",{value:e,enumerable:!0}):t,e)),nt=e=>xe(K({},"__esModule",{value:!0}),e);var rr={};G(rr,{AzureDevOps:()=>Q,AzureDevopsUtils:()=>te,Bitbucket:()=>B,BitbucketServer:()=>j,BitbucketServerUtils:()=>se,BitbucketUtils:()=>re,GitHub:()=>F,GitHubUtils:()=>ne,GitLab:()=>z,GitLabUtils:()=>oe,Jira:()=>H,JiraUtils:()=>ae,Trello:()=>J,TrelloUtils:()=>ie,Utils:()=>tr,default:()=>er});module.exports=nt(rr);var v=100;var Te=st(require("node-fetch")),Ae=globalThis.fetch||Te.default;var Oe=e=>e.name==="fetch";var ot=async e=>{let r=e.headers.get("content-type")||"",t=null;if(r.startsWith("application/json"))t=await e.json();else if(r.startsWith("text/"))t=await e.text();else throw new Error(`Unsupported content-type: ${r}`);let s={body:t,headers:Object.fromEntries(e.headers.entries()),status:e.status,statusText:e.statusText};if(!e.ok){let n=new Error(e.statusText);throw Object.assign(n,{response:s}),n}return s},ue=e=>Oe(e)?async({url:r,...t})=>{let s=await e(r,t);return ot(s)}:e;var $=class{constructor(r){this.config={...r,request:ue((r==null?void 0:r.request)||Ae)}}updateConfig(r){this.config={...this.config,...r,request:r.request?ue(r.request):this.config.request}}},x=class extends ${};var m=(e,r)=>{let t={};return e&&(t.Authorization=`${r?"Basic":"Bearer"} ${e}`),t};var C=(e,r={})=>m(r.token||e.token,r.isPAT||e.isPAT),ke=e=>e.url.replace("/_apis/git/repositories/","/_git/").replace(`/${e.repository.project.id}/`,`/${encodeURIComponent(e.repository.project.name)}/`).replace(`/${e.repository.id}/`,`/${encodeURIComponent(e.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var _e="https://app.vssps.visualstudio.com/_apis",E="https://dev.azure.com",at={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},it={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},le=e=>({id:e.id,name:e.displayName,username:e.uniqueName||e.displayName,email:null,avatarUrl:e.imageUrl}),X=e=>e.startsWith("refs/heads/")?e.replace("refs/heads/",""):e,Ne=e=>{var r;return{id:e.pullRequestId.toString(),title:e.title,number:e.codeReviewId,state:at[e.status],isDraft:e.isDraft,commentCount:null,upvoteCount:null,author:le(e.createdBy),createdDate:new Date(e.creationDate),updatedDate:new Date(e.closedDate||e.creationDate),closedDate:e.closedDate?new Date(e.closedDate):null,repository:{name:e.repository.name,owner:{login:void 0}},headCommit:{buildStatus:null},baseRef:{name:X(e.targetRefName)},headRef:{name:X(e.sourceRefName)},url:ke(e),assignees:e.reviewers.map(le),reviews:e.reviewers.filter(t=>t.vote!==0).map(t=>({reviewer:le(t),state:it[t.vote]||"REVIEW_REQUESTED"})),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((r=e.labels)==null?void 0:r.map(t=>({color:null,description:null,id:t.id,name:t.name})))??[]}},Qe=(e,r)=>({id:r.id,name:r.name,namespace:e,project:r.project.name,webUrl:r.webUrl,httpsUrl:r.remoteUrl,sshUrl:r.sshUrl,defaultBranch:r.defaultBranch?{name:X(r.defaultBranch)}:null,permission:null}),ut=(e,r)=>{var i,u;let t=e.fields,s=t["System.AssignedTo"],n=t["System.State"],a=t["System.WorkItemType"],o;return n&&a&&(o=(i=r[a])==null?void 0:i[n]),{id:e.id.toString(),number:e.id.toString(),title:t["System.Title"],commentCount:t["System.CommentCount"],author:{avatarUrl:t["System.CreatedBy"]._links.avatar.href,email:null,id:t["System.CreatedBy"].id,name:t["System.CreatedBy"].uniqueName,username:t["System.CreatedBy"].displayName},createdDate:new Date(t["System.CreatedDate"]),updatedDate:new Date(t["System.ChangedDate"]),url:e._links.html.href,assignees:s?[{avatarUrl:s._links.avatar.href,email:null,id:s.id,name:s.uniqueName,username:s.displayName}]:[],description:null,state:{name:(o==null?void 0:o.title)||n,color:null},type:t["System.WorkItemType"],repository:null,upvoteCount:0,labels:((u=e.fields["System.Tags"])==null?void 0:u.split(";").map(l=>({color:null,description:null,id:null,name:l.trim()})))??[]}},Q=class extends ${async getCurrentUser(r={}){if(r.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let t=await this.config.request({url:`${_e}/profile/profiles/me`,headers:C(this.config,r)});return{data:{id:t.body.id,name:t.body.displayName,username:t.body.displayName,email:t.body.emailAddress,avatarUrl:null}}}async getCurrentUserForInstance(r,t={}){let n=(await this.config.request({url:`${E}/${encodeURIComponent(r.namespace)}/_apis/ConnectionData`,headers:C(this.config,t)})).body.authorizedUser;if(n.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:n.id,name:n.providerDisplayName,username:n.providerDisplayName,email:n.properties.Account.$value,avatarUrl:null}}}async getUserForCommit(r,t={}){if(!r.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${E}/${encodeURIComponent(r.repo.namespace)}/${encodeURIComponent(r.repo.project)}/_apis/git/repositories/${encodeURIComponent(r.repo.name)}/commits/${r.oid}`,headers:C(this.config,t)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(r,t={}){return{data:(await this.config.request({url:`${_e}/accounts?memberId=${r.userId}&api-version=6.0`,headers:C(this.config,t)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(r,t={}){let s=new URL(`${E}/${encodeURIComponent(r.namespace)}/_apis/projects`);s.searchParams.set("$top",v.toString()),r.cursor&&s.searchParams.set("$skip",r.cursor);let n=await this.config.request({url:s.toString(),headers:C(this.config,t)}),a=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:n.body.value.map(o=>({id:o.id,name:o.name,namespace:r.namespace}))}}async getRepo(r,t={}){if(!r.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=await this.config.request({url:`${E}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/git/repositories/${encodeURIComponent(r.name)}`,headers:C(this.config,t)});return{data:Qe(r.namespace,s.body)}}async getRepos(r,t={}){let s=[],n=[];return await Promise.all(r.map(async a=>{try{let o=await this.getRepo(a,t);s.push(o.data)}catch(o){n.push({input:a,error:o})}})),{data:s,errors:n}}async getReposForAzureProject(r,t={}){if(!r.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${E}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/git/repositories`,headers:C(this.config,t)})).body.value.map(n=>Qe(r.namespace,n))}}async getRefs(r,t,s={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${E}/${encodeURIComponent(t.repo.namespace)}/${encodeURIComponent(t.repo.project)}/_apis/git/repositories/${encodeURIComponent(t.repo.name)}/refs`);n.searchParams.set("filter",r),n.searchParams.set("$top",v.toString()),t.cursor&&n.searchParams.set("continuationToken",t.cursor);let a=await this.config.request({url:n.toString(),headers:C(this.config,s)}),o=a.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:a.body.value.map(i=>({name:X(i.name),commit:{oid:i.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(r,t={}){return this.getRefs("heads",r,t)}async getTags(r,t={}){return this.getRefs("tags",r,t)}async getPullRequestsForRepoBase(r,t={},s=100){let{page:n,repo:a,assigneeLogins:o,authorLogin:i}=r||{},u=n||1;if(!a.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return o&&o.length&&(l+=`&searchCriteria.reviewerId=${o[0]}`),i&&(l+=`&searchCriteria.creatorId=${i}`),await this.config.request({url:`${t.baseUrl||E}/${encodeURIComponent(a.namespace)}/${encodeURIComponent(a.project||"")}/_apis/git/repositories/${encodeURIComponent(a.name)}/pullRequests?${l}&%24top=${s}&%24skip=${(u-1)*s}`,headers:C(this.config,t)})}async getPullRequestsForRepo(r,t={}){let n=r.page||1,a=await this.getPullRequestsForRepoBase(r,t,100);return{pageInfo:{hasNextPage:a.body.value.length===100,nextPage:n+1},data:a.body.value.map(Ne)}}async getPullRequestsForRepos(r,t={}){if(!r.repos.every(a=>a.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:s}=r||{},n=[];return await Promise.all(s.map(async a=>{try{(await this.getPullRequestsForRepoBase({repo:a,...r},t)).body.value.forEach(i=>{n.push(Ne(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:n}}async updatePullRequest(r,t,s,n){let{namespace:a,project:o,name:i}=r;return await this.config.request({method:"PATCH",url:`${n.baseUrl||E}/${encodeURIComponent(a)}/${encodeURIComponent(o||"")}/_apis/git/repositories/${i}/pullrequests/${t}?api-version=6.0`,body:s,headers:{...C(this.config,n),"Content-Type":"application/json"}})}async closePullRequest(r,t={}){if(!r.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:s,pullRequestId:n}=r,a={status:"abandoned"};if(!(await this.updatePullRequest(s,n,JSON.stringify(a),t)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(r,t={}){if(!r.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:s,pullRequestId:n,expectedSourceSha:a}=r,o={lastMergeSourceCommit:{commitId:a},status:"completed"};if(!(await this.updatePullRequest(s,n,JSON.stringify(o),t)).body.status)throw new Error("Could not merge pull request")}async setPullRequestAsDraft(r,t={}){if(!r.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:s,pullRequestId:n,isDraft:a}=r,o={isDraft:a};if(!(await this.updatePullRequest(s,n,JSON.stringify(o),t)).body.status)throw new Error("Could not set the pull request as draft")}async getIssuesForAzureProject(r,t={}){let{page:s,assigneeLogins:n,authorLogin:a,mentionLogin:o,statusByWorkItemIdByStatusId:i}=r||{},u=s||1,l=200,p=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];a&&p.push(`[System.CreatedBy] = '${a.replace("'","''")}'`),n&&n[0]&&p.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),o&&p.push("[System.Id] IN (@recentMentions)");let d=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${p.join(" AND ")} order by [System.CreatedDate] desc`,c=await this.config.request({url:`${t.baseUrl||E}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:d}),method:"POST",headers:{...C(this.config,t),"Content-Type":"application/json"}}),g=c.body.workItems.slice((u-1)*l,l*u).map(I=>I.id);if(g.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let R=await this.config.request({url:`${t.baseUrl||E}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:g,$expand:"Links"}),method:"POST",headers:{...C(this.config,t),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:c.body.workItems.length>l*u,nextPage:u+1},data:R.body.value.map(I=>ut(I,i||{}))}}async setIssueStatus(r,t={}){var l;if(!r.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:s,project:n,issueId:a,status:o}=r,i=[{op:"add",path:"/fields/System.State",value:o}];if(!((l=(await this.config.request({method:"PATCH",url:`${t.baseUrl||E}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/wit/workitems/${a}?api-version=6.0`,body:JSON.stringify(i),headers:{...C(this.config,t),"Content-Type":"application/json-patch+json"}})).body.fields)!=null&&l["System.State"]))throw new Error("Could not set issue status")}async getIssueTypesForAzureProject(r,t={}){if(!r.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:s,project:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||E}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...C(this.config,t)}})).body.value}}async getLabelsForProject(r,t={}){let{namespace:s,project:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||E}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...C(this.config,t)}})).body.value.map(o=>({color:null,description:null,id:o.id,name:o.name}))}}};var D=(e,r={})=>m(r.token||e.token,r.isPAT||e.isPAT);var q="https://api.bitbucket.org/2.0",lt={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},Fe=e=>({id:e.uuid,name:e.display_name||e.nickname,username:e.nickname||e.display_name,email:null,avatarUrl:e.links.avatar.href}),Be=e=>{var r,t;return{id:e.uuid,namespace:e.workspace.slug,name:e.slug,webUrl:e.links.html.href,httpsUrl:((r=e.links.clone.find(s=>s.name==="https"))==null?void 0:r.href)??null,sshUrl:((t=e.links.clone.find(s=>s.name==="ssh"))==null?void 0:t.href)??null,defaultBranch:{name:e.mainbranch.name},permission:null}},je=e=>{let r=e.id;return{id:r.toString(),title:e.title,number:r,state:lt[e.state],isDraft:!1,commentCount:e.comment_count,upvoteCount:null,author:Fe(e.author),createdDate:new Date(e.created_on),updatedDate:new Date(e.updated_on),closedDate:null,repository:{name:e.source.repository.name,owner:{login:void 0}},headCommit:{buildStatus:null},baseRef:{name:e.destination.branch.name},headRef:{name:e.source.branch.name},url:e.links.html.href,assignees:null,reviews:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN"}},B=class extends ${async refreshToken(r){return{data:(await this.config.request({url:"https://bitbucket.org/site/oauth2/access_token",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${r.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${r.refreshToken}`})).body}}async getCurrentUser(r={}){let t=await this.config.request({url:`${q}/user`,headers:D(this.config,r)});return{data:Fe(t.body)}}async getUserForCommit(r,t={}){var o;let n=(await this.config.request({url:`${q}/repositories/${r.repo.namespace}/${r.repo.name}/commit/${r.oid}`,headers:D(this.config,t)})).body.author,a=n.raw.match(/([^<]+)<(.+)>/);return{data:{name:a?a[1].trim():null,email:a?a[2]:null,avatarUrl:((o=n.user)==null?void 0:o.links.avatar.href)||null}}}async getRepo(r,t={}){let s=await this.config.request({url:`${q}/repositories/${r.namespace}/${r.name}`,headers:D(this.config,t)});return{data:Be(s.body)}}async getRepos(r,t={}){let s=[],n=[];return await Promise.all(r.map(async a=>{try{let o=await this.getRepo(a,t);s.push(o.data)}catch(o){n.push({input:a,error:o})}})),{data:s,errors:n}}async getReposForCurrentUser(r={},t={}){let s=new URL(`${q}/repositories`);s.searchParams.set("role","member"),s.searchParams.set("pagelen",v.toString()),r.cursor&&s.searchParams.set("after",r.cursor);let n=await this.config.request({url:s.toString(),headers:D(this.config,t)}),a=!!n.body.next,o=null;return n.body.next&&(o=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:a,endCursor:o},data:n.body.values.map(Be)}}async getBranches(r,t={}){var o;let s=new URL(`${q}/repositories/${r.repo.namespace}/${r.repo.name}/refs/branches`);s.searchParams.set("page",((o=r.page)==null?void 0:o.toString())||"1"),s.searchParams.set("pagelen",v.toString());let n=await this.config.request({url:s.toString(),headers:D(this.config,t)}),a=!!n.body.next;return{pageInfo:{hasNextPage:a,nextPage:a?n.body.page+1:null},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getTags(r,t={}){let s=new URL(`${q}/repositories/${r.repo.namespace}/${r.repo.name}/refs/tags`);s.searchParams.set("pagelen",v.toString()),r.cursor&&s.searchParams.set("page",r.cursor);let n=await this.config.request({url:s.toString(),headers:D(this.config,t)}),a=!!n.body.next,o=null;return n.body.next&&(o=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:a,endCursor:o},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getPullRequestsForRepoBase(r,t={}){var n;let s=new URL(`${q}/repositories/${encodeURI(r.repo.namespace)}/${encodeURI(r.repo.name)}/pullrequests?state=OPEN`);return s.searchParams.set("page",((n=r.page)==null?void 0:n.toString())||"1"),s.searchParams.set("pagelen","50"),await this.config.request({url:s.toString(),headers:D(this.config,t)})}async getPullRequestsForRepo(r,t={}){let s=[],n=await this.getPullRequestsForRepoBase(r,t);n.body.values.forEach(o=>{if(r.authorLogin&&o.author.uuid!==r.authorLogin)return null;s.push(je(o))});let a=!!n.body.next;return{pageInfo:{hasNextPage:a,nextPage:a?n.body.page+1:null},data:s}}async getPullRequestsForRepos(r,t={}){let s=[];return await Promise.all(r.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...r},t)).body.values.forEach(o=>{if(r.authorLogin&&o.author.uuid!==r.authorLogin)return null;s.push(je(o))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:s}}async closePullRequest(r,t={}){let{repo:{namespace:s,name:n},pullRequestId:a}=r;if(!(await this.config.request({method:"POST",url:`${q}/repositories/${s}/${n}/pullrequests/${a}/decline`,headers:D(this.config,t)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(r,t={}){let{repo:{namespace:s,name:n},pullRequestId:a}=r;if(!(await this.config.request({method:"POST",url:`${q}/repositories/${s}/${n}/pullrequests/${a}/merge`,headers:D(this.config,t)})).body.title)throw new Error("Could not merge pull request")}};var j=class extends x{getBaseUrl(r){let t=r.baseUrl||this.config.baseUrl;if(!t)throw new Error('Bitbucket Server requires "baseUrl"');return t}getRequestHeaders(r){return m(r.token||this.config.token)}async getRepo(r,t={}){var n,a,o;let s=await this.config.request({url:`${this.getBaseUrl(t)}/projects/${r.namespace}/repos/${r.name}`,headers:this.getRequestHeaders(t)});return{data:{id:s.body.id.toString(),namespace:s.body.project.key,name:s.body.slug,webUrl:((n=s.body.links.self[0])==null?void 0:n.href)??null,httpsUrl:((a=s.body.links.clone.find(i=>i.name==="https"))==null?void 0:a.href)??null,sshUrl:((o=s.body.links.clone.find(i=>i.name==="ssh"))==null?void 0:o.href)??null,defaultBranch:null,permission:null}}}async getRepos(r,t={}){let s=[],n=[];return await Promise.all(r.map(async a=>{try{let o=await this.getRepo(a,t);s.push(o.data)}catch(o){n.push({input:a,error:o})}})),{data:s,errors:n}}};var ce="https://api.github.com",pt=`${ce}/graphql`,Y=`
1
+ "use strict";var Ze=Object.create;var K=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var et=Object.getOwnPropertyNames;var tt=Object.getPrototypeOf,rt=Object.prototype.hasOwnProperty;var x=(e,r)=>{for(var t in r)K(e,t,{get:r[t],enumerable:!0})},Ae=(e,r,t,s)=>{if(r&&typeof r=="object"||typeof r=="function")for(let n of et(r))!rt.call(e,n)&&n!==t&&K(e,n,{get:()=>r[n],enumerable:!(s=Ye(r,n))||s.enumerable});return e};var st=(e,r,t)=>(t=e!=null?Ze(tt(e)):{},Ae(r||!e||!e.__esModule?K(t,"default",{value:e,enumerable:!0}):t,e)),nt=e=>Ae(K({},"__esModule",{value:!0}),e);var rr={};x(rr,{AzureDevOps:()=>B,AzureDevopsUtils:()=>te,Bitbucket:()=>j,BitbucketServer:()=>F,BitbucketServerUtils:()=>se,BitbucketUtils:()=>re,GitHub:()=>M,GitHubUtils:()=>ne,GitLab:()=>W,GitLabUtils:()=>oe,Jira:()=>J,JiraUtils:()=>ae,Trello:()=>V,TrelloUtils:()=>ie,Utils:()=>tr,default:()=>er});module.exports=nt(rr);var C=100;var Oe=st(require("node-fetch")),ke=globalThis.fetch||Oe.default;var _e=e=>e.name==="fetch";var ot=async e=>{let r=e.headers.get("content-type")||"",t=null;if(r.startsWith("application/json"))e.body!==null&&e.size!==0&&(t=await e.json());else if(r.startsWith("text/"))t=await e.text();else throw new Error(`Unsupported content-type: ${r}`);let s={body:t,headers:Object.fromEntries(e.headers.entries()),status:e.status,statusText:e.statusText};if(!e.ok){let n=new Error(e.statusText);throw Object.assign(n,{response:s}),n}return s},le=e=>_e(e)?async({url:r,...t})=>{let s=await e(r,t);return ot(s)}:e;var E=class{constructor(r){this.config={...r,request:le((r==null?void 0:r.request)||ke)}}updateConfig(r){this.config={...this.config,...r,request:r.request?le(r.request):this.config.request}}},T=class extends E{};var m=(e,r)=>{let t={};return e&&(t.Authorization=`${r?"Basic":"Bearer"} ${e}`),t};var w=(e,r={})=>m(r.token||e.token,r.isPAT||e.isPAT),Ne=e=>e.url.replace("/_apis/git/repositories/","/_git/").replace(`/${e.repository.project.id}/`,`/${encodeURIComponent(e.repository.project.name)}/`).replace(`/${e.repository.id}/`,`/${encodeURIComponent(e.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var Qe="https://app.vssps.visualstudio.com/_apis",$="https://dev.azure.com",at={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},it={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},pe=e=>({id:e.id,name:e.displayName,username:e.uniqueName||e.displayName,email:null,avatarUrl:e.imageUrl}),X=e=>e.startsWith("refs/heads/")?e.replace("refs/heads/",""):e,Be=e=>{var r;return{id:e.pullRequestId.toString(),title:e.title,number:e.codeReviewId,state:at[e.status],isDraft:e.isDraft,commentCount:null,upvoteCount:null,author:pe(e.createdBy),createdDate:new Date(e.creationDate),updatedDate:new Date(e.closedDate||e.creationDate),closedDate:e.closedDate?new Date(e.closedDate):null,repository:{name:e.repository.name,owner:{login:void 0}},headCommit:{buildStatus:null},baseRef:{name:X(e.targetRefName),oid:e.lastMergeTargetCommit.commitId},headRef:{name:X(e.sourceRefName),oid:e.lastMergeSourceCommit.commitId},url:Ne(e),assignees:e.reviewers.map(pe),reviews:e.reviewers.filter(t=>t.vote!==0).map(t=>({reviewer:pe(t),state:it[t.vote]||"REVIEW_REQUESTED"})),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((r=e.labels)==null?void 0:r.map(t=>({color:null,description:null,id:t.id,name:t.name})))??[]}},je=(e,r)=>({id:r.id,name:r.name,namespace:e,project:r.project.name,webUrl:r.webUrl,httpsUrl:r.remoteUrl,sshUrl:r.sshUrl,defaultBranch:r.defaultBranch?{name:X(r.defaultBranch)}:null,permission:null}),ut=(e,r)=>{var i,u;let t=e.fields,s=t["System.AssignedTo"],n=t["System.State"],a=t["System.WorkItemType"],o;return n&&a&&(o=(i=r[a])==null?void 0:i[n]),{id:e.id.toString(),number:e.id.toString(),title:t["System.Title"],commentCount:t["System.CommentCount"],author:{avatarUrl:t["System.CreatedBy"]._links.avatar.href,email:null,id:t["System.CreatedBy"].id,name:t["System.CreatedBy"].uniqueName,username:t["System.CreatedBy"].displayName},createdDate:new Date(t["System.CreatedDate"]),updatedDate:new Date(t["System.ChangedDate"]),url:e._links.html.href,assignees:s?[{avatarUrl:s._links.avatar.href,email:null,id:s.id,name:s.uniqueName,username:s.displayName}]:[],description:null,state:{name:(o==null?void 0:o.title)||n,color:null},type:t["System.WorkItemType"],repository:null,upvoteCount:0,labels:((u=e.fields["System.Tags"])==null?void 0:u.split(";").map(l=>({color:null,description:null,id:null,name:l.trim()})))??[]}},B=class extends E{async getCurrentUser(r={}){if(r.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let t=await this.config.request({url:`${Qe}/profile/profiles/me`,headers:w(this.config,r)});return{data:{id:t.body.id,name:t.body.displayName,username:t.body.displayName,email:t.body.emailAddress,avatarUrl:null}}}async getCurrentUserForInstance(r,t={}){let n=(await this.config.request({url:`${$}/${encodeURIComponent(r.namespace)}/_apis/ConnectionData`,headers:w(this.config,t)})).body.authorizedUser;if(n.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:n.id,name:n.providerDisplayName,username:n.providerDisplayName,email:n.properties.Account.$value,avatarUrl:null}}}async getUserForCommit(r,t={}){if(!r.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${$}/${encodeURIComponent(r.repo.namespace)}/${encodeURIComponent(r.repo.project)}/_apis/git/repositories/${encodeURIComponent(r.repo.name)}/commits/${r.oid}`,headers:w(this.config,t)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(r,t={}){return{data:(await this.config.request({url:`${Qe}/accounts?memberId=${r.userId}&api-version=6.0`,headers:w(this.config,t)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(r,t={}){let s=new URL(`${$}/${encodeURIComponent(r.namespace)}/_apis/projects`);s.searchParams.set("$top",C.toString()),r.cursor&&s.searchParams.set("$skip",r.cursor);let n=await this.config.request({url:s.toString(),headers:w(this.config,t)}),a=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:n.body.value.map(o=>({id:o.id,name:o.name,namespace:r.namespace}))}}async getRepo(r,t={}){if(!r.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let s=await this.config.request({url:`${$}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/git/repositories/${encodeURIComponent(r.name)}`,headers:w(this.config,t)});return{data:je(r.namespace,s.body)}}async getRepos(r,t={}){let s=[],n=[];return await Promise.all(r.map(async a=>{try{let o=await this.getRepo(a,t);s.push(o.data)}catch(o){n.push({input:a,error:o})}})),{data:s,errors:n}}async getReposForAzureProject(r,t={}){if(!r.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${$}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/git/repositories`,headers:w(this.config,t)})).body.value.map(n=>je(r.namespace,n))}}async getRefs(r,t,s={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${$}/${encodeURIComponent(t.repo.namespace)}/${encodeURIComponent(t.repo.project)}/_apis/git/repositories/${encodeURIComponent(t.repo.name)}/refs`);n.searchParams.set("filter",r),n.searchParams.set("$top",C.toString()),t.cursor&&n.searchParams.set("continuationToken",t.cursor);let a=await this.config.request({url:n.toString(),headers:w(this.config,s)}),o=a.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:a.body.value.map(i=>({name:X(i.name),commit:{oid:i.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(r,t={}){return this.getRefs("heads",r,t)}async getTags(r,t={}){return this.getRefs("tags",r,t)}async getPullRequestsForRepoBase(r,t={},s=100){let{page:n,repo:a,assigneeLogins:o,authorLogin:i}=r||{},u=n||1;if(!a.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return o&&o.length&&(l+=`&searchCriteria.reviewerId=${o[0]}`),i&&(l+=`&searchCriteria.creatorId=${i}`),await this.config.request({url:`${t.baseUrl||$}/${encodeURIComponent(a.namespace)}/${encodeURIComponent(a.project||"")}/_apis/git/repositories/${encodeURIComponent(a.name)}/pullRequests?${l}&%24top=${s}&%24skip=${(u-1)*s}`,headers:w(this.config,t)})}async getPullRequestsForRepo(r,t={}){let n=r.page||1,a=await this.getPullRequestsForRepoBase(r,t,100);return{pageInfo:{hasNextPage:a.body.value.length===100,nextPage:n+1},data:a.body.value.map(Be)}}async getPullRequestsForRepos(r,t={}){if(!r.repos.every(a=>a.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:s}=r||{},n=[];return await Promise.all(s.map(async a=>{try{(await this.getPullRequestsForRepoBase({repo:a,...r},t)).body.value.forEach(i=>{n.push(Be(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:n}}async updatePullRequest(r,t,s,n){let{namespace:a,project:o,name:i}=r;return await this.config.request({method:"PATCH",url:`${n.baseUrl||$}/${encodeURIComponent(a)}/${encodeURIComponent(o||"")}/_apis/git/repositories/${i}/pullrequests/${t}?api-version=6.0`,body:s,headers:{...w(this.config,n),"Content-Type":"application/json"}})}async closePullRequest(r,t={}){if(!r.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:s,pullRequestId:n}=r,a={status:"abandoned"};if(!(await this.updatePullRequest(s,n,JSON.stringify(a),t)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(r,t={}){if(!r.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:s,pullRequestId:n,expectedSourceSha:a}=r,o={lastMergeSourceCommit:{commitId:a},status:"completed"};if(!(await this.updatePullRequest(s,n,JSON.stringify(o),t)).body.status)throw new Error("Could not merge pull request")}async setPullRequestAsDraft(r,t={}){if(!r.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:s,pullRequestId:n,isDraft:a}=r,o={isDraft:a};if(!(await this.updatePullRequest(s,n,JSON.stringify(o),t)).body.status)throw new Error("Could not set the pull request as draft")}async getIssuesForAzureProject(r,t={}){let{page:s,assigneeLogins:n,authorLogin:a,mentionLogin:o,statusByWorkItemIdByStatusId:i}=r||{},u=s||1,l=200,p=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];a&&p.push(`[System.CreatedBy] = '${a.replace("'","''")}'`),n&&n[0]&&p.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),o&&p.push("[System.Id] IN (@recentMentions)");let d=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${p.join(" AND ")} order by [System.CreatedDate] desc`,c=await this.config.request({url:`${t.baseUrl||$}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:d}),method:"POST",headers:{...w(this.config,t),"Content-Type":"application/json"}}),g=c.body.workItems.slice((u-1)*l,l*u).map(I=>I.id);if(g.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let R=await this.config.request({url:`${t.baseUrl||$}/${encodeURIComponent(r.namespace)}/${encodeURIComponent(r.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:g,$expand:"Links"}),method:"POST",headers:{...w(this.config,t),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:c.body.workItems.length>l*u,nextPage:u+1},data:R.body.value.map(I=>ut(I,i||{}))}}async setIssueStatus(r,t={}){var l;if(!r.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:s,project:n,issueId:a,status:o}=r,i=[{op:"add",path:"/fields/System.State",value:o}];if(!((l=(await this.config.request({method:"PATCH",url:`${t.baseUrl||$}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/wit/workitems/${a}?api-version=6.0`,body:JSON.stringify(i),headers:{...w(this.config,t),"Content-Type":"application/json-patch+json"}})).body.fields)!=null&&l["System.State"]))throw new Error("Could not set issue status")}async getIssueTypesForAzureProject(r,t={}){if(!r.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:s,project:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||$}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...w(this.config,t)}})).body.value}}async getLabelsForProject(r,t={}){let{namespace:s,project:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||$}/${encodeURIComponent(s)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...w(this.config,t)}})).body.value.map(o=>({color:null,description:null,id:o.id,name:o.name}))}}};var S=(e,r={})=>m(r.token||e.token,r.isPAT||e.isPAT);var U="https://api.bitbucket.org/2.0",lt={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},Me=e=>({id:e.uuid,name:e.display_name||e.nickname,username:e.nickname||e.display_name,email:null,avatarUrl:e.links.avatar.href}),Fe=e=>{var r,t;return{id:e.uuid,namespace:e.workspace.slug,name:e.slug,webUrl:e.links.html.href,httpsUrl:((r=e.links.clone.find(s=>s.name==="https"))==null?void 0:r.href)??null,sshUrl:((t=e.links.clone.find(s=>s.name==="ssh"))==null?void 0:t.href)??null,defaultBranch:{name:e.mainbranch.name},permission:null}},ge=e=>{let r=e.id;return{id:r.toString(),title:e.title,number:r,state:lt[e.state],isDraft:!1,commentCount:e.comment_count,upvoteCount:null,author:Me(e.author),createdDate:new Date(e.created_on),updatedDate:new Date(e.updated_on),closedDate:null,repository:{name:e.source.repository.name,owner:{login:void 0}},headCommit:{buildStatus:null},baseRef:{name:e.destination.branch.name,oid:e.destination.commit.hash},headRef:{name:e.source.branch.name,oid:e.source.commit.hash},url:e.links.html.href,assignees:null,reviews:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN"}},j=class extends E{async refreshToken(r){return{data:(await this.config.request({url:"https://bitbucket.org/site/oauth2/access_token",method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded",Authorization:`Basic ${r.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${r.refreshToken}`})).body}}async getCurrentUser(r={}){let t=await this.config.request({url:`${U}/user`,headers:S(this.config,r)});return{data:Me(t.body)}}async getUserForCommit(r,t={}){var o;let n=(await this.config.request({url:`${U}/repositories/${r.repo.namespace}/${r.repo.name}/commit/${r.oid}`,headers:S(this.config,t)})).body.author,a=n.raw.match(/([^<]+)<(.+)>/);return{data:{name:a?a[1].trim():null,email:a?a[2]:null,avatarUrl:((o=n.user)==null?void 0:o.links.avatar.href)||null}}}async getRepo(r,t={}){let s=await this.config.request({url:`${U}/repositories/${r.namespace}/${r.name}`,headers:S(this.config,t)});return{data:Fe(s.body)}}async getRepos(r,t={}){let s=[],n=[];return await Promise.all(r.map(async a=>{try{let o=await this.getRepo(a,t);s.push(o.data)}catch(o){n.push({input:a,error:o})}})),{data:s,errors:n}}async getReposForCurrentUser(r={},t={}){let s=new URL(`${U}/repositories`);s.searchParams.set("role","member"),s.searchParams.set("pagelen",C.toString()),r.cursor&&s.searchParams.set("after",r.cursor);let n=await this.config.request({url:s.toString(),headers:S(this.config,t)}),a=!!n.body.next,o=null;return n.body.next&&(o=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:a,endCursor:o},data:n.body.values.map(Fe)}}async getBranches(r,t={}){var o;let s=new URL(`${U}/repositories/${r.repo.namespace}/${r.repo.name}/refs/branches`);s.searchParams.set("page",((o=r.page)==null?void 0:o.toString())||"1"),s.searchParams.set("pagelen",C.toString());let n=await this.config.request({url:s.toString(),headers:S(this.config,t)}),a=!!n.body.next;return{pageInfo:{hasNextPage:a,nextPage:a?n.body.page+1:null},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getTags(r,t={}){let s=new URL(`${U}/repositories/${r.repo.namespace}/${r.repo.name}/refs/tags`);s.searchParams.set("pagelen",C.toString()),r.cursor&&s.searchParams.set("page",r.cursor);let n=await this.config.request({url:s.toString(),headers:S(this.config,t)}),a=!!n.body.next,o=null;return n.body.next&&(o=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:a,endCursor:o},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getPullRequestsForUser(r,t={}){var o;let s=new URL(`${U}/pullrequests/${r.userId}`);s.searchParams.set("page",((o=r.page)==null?void 0:o.toString())||"1"),s.searchParams.set("pagelen","50");let n=await this.config.request({url:`${U}/pullrequests/${r.userId}`,headers:S(this.config,t)}),a=!!n.body.next;return{pageInfo:{hasNextPage:a,nextPage:a?n.body.page+1:null},data:n.body.values.map(ge)}}async getPullRequestsForRepoBase(r,t={}){var n;let s=new URL(`${U}/repositories/${encodeURI(r.repo.namespace)}/${encodeURI(r.repo.name)}/pullrequests?state=OPEN`);return s.searchParams.set("page",((n=r.page)==null?void 0:n.toString())||"1"),s.searchParams.set("pagelen","50"),await this.config.request({url:s.toString(),headers:S(this.config,t)})}async getPullRequestsForRepo(r,t={}){let s=[],n=await this.getPullRequestsForRepoBase(r,t);n.body.values.forEach(o=>{if(r.authorLogin&&o.author.uuid!==r.authorLogin)return null;s.push(ge(o))});let a=!!n.body.next;return{pageInfo:{hasNextPage:a,nextPage:a?n.body.page+1:null},data:s}}async getPullRequestsForRepos(r,t={}){let s=[];return await Promise.all(r.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...r},t)).body.values.forEach(o=>{if(r.authorLogin&&o.author.uuid!==r.authorLogin)return null;s.push(ge(o))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:s}}async closePullRequest(r,t={}){let{repo:{namespace:s,name:n},pullRequestId:a}=r;if(!(await this.config.request({method:"POST",url:`${U}/repositories/${s}/${n}/pullrequests/${a}/decline`,headers:S(this.config,t)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(r,t={}){let{repo:{namespace:s,name:n},pullRequestId:a}=r;if(!(await this.config.request({method:"POST",url:`${U}/repositories/${s}/${n}/pullrequests/${a}/merge`,headers:S(this.config,t)})).body.title)throw new Error("Could not merge pull request")}};var F=class extends T{getBaseUrl(r){let t=r.baseUrl||this.config.baseUrl;if(!t)throw new Error('Bitbucket Server requires "baseUrl"');return t}getRequestHeaders(r){return m(r.token||this.config.token)}async getRepo(r,t={}){var n,a,o;let s=await this.config.request({url:`${this.getBaseUrl(t)}/projects/${r.namespace}/repos/${r.name}`,headers:this.getRequestHeaders(t)});return{data:{id:s.body.id.toString(),namespace:s.body.project.key,name:s.body.slug,webUrl:((n=s.body.links.self[0])==null?void 0:n.href)??null,httpsUrl:((a=s.body.links.clone.find(i=>i.name==="https"))==null?void 0:a.href)??null,sshUrl:((o=s.body.links.clone.find(i=>i.name==="ssh"))==null?void 0:o.href)??null,defaultBranch:null,permission:null}}}async getRepos(r,t={}){let s=[],n=[];return await Promise.all(r.map(async a=>{try{let o=await this.getRepo(a,t);s.push(o.data)}catch(o){n.push({input:a,error:o})}})),{data:s,errors:n}}};var me="https://api.github.com",pt=`${me}/graphql`,Y=`
2
2
  description
3
3
  dueOn
4
4
  id
@@ -6,12 +6,12 @@ number
6
6
  state
7
7
  title
8
8
  url
9
- `,Me=/\/api\/v\d+$/,ee=`
9
+ `,ze=/\/api\/v\d+$/,ee=`
10
10
  color
11
11
  description
12
12
  id
13
13
  name
14
- `,dt=e=>{if(e.endsWith("/api/graphql"))throw new Error("The graphql endpoint is being used as the baseUrl. This package uses both GraphQL and REST APIs, and the REST version cannot be assumed. Use the REST endpoint as the baseUrl instead.")},ct=(e,r)=>{let t=r.baseUrl||e.baseUrl;return t?(t=t.replace(/\/$/,""),dt(t),Me.test(t)&&(t=t.replace(Me,"")),`${t}/api/graphql`):pt},h=(e,r,t)=>{let s=m(t.token||e.token);return s["X-Github-Next-Global-ID"]="1",s["Content-Type"]="application/json",e.request({url:ct(e,t),method:"POST",headers:s,body:JSON.stringify(r)})},gt={user:!0,"user:email":!0,"read:user":!0},O=e=>e.some(r=>gt[r]),U=(e=!1,r=!1)=>`
14
+ `,dt=e=>{if(e.endsWith("/api/graphql"))throw new Error("The graphql endpoint is being used as the baseUrl. This package uses both GraphQL and REST APIs, and the REST version cannot be assumed. Use the REST endpoint as the baseUrl instead.")},ct=(e,r)=>{let t=r.baseUrl||e.baseUrl;return t?(t=t.replace(/\/$/,""),dt(t),ze.test(t)&&(t=t.replace(ze,"")),`${t}/api/graphql`):pt},h=(e,r,t)=>{let s=m(t.token||e.token);return s["X-Github-Next-Global-ID"]="1",s["Content-Type"]="application/json",e.request({url:ct(e,t),method:"POST",headers:s,body:JSON.stringify(r)})},gt={user:!0,"user:email":!0,"read:user":!0},k=e=>e.some(r=>gt[r]),q=(e=!1,r=!1)=>`
15
15
  __typename
16
16
  id
17
17
  databaseId
@@ -19,7 +19,7 @@ name
19
19
  login
20
20
  ${r?"email":""}
21
21
  avatarUrl${e?"(size: $avatarSize)":""}
22
- `,ze=(e=!1)=>`
22
+ `,We=(e=!1)=>`
23
23
  __typename
24
24
  id
25
25
  databaseId
@@ -33,10 +33,10 @@ title
33
33
  state
34
34
  author {
35
35
  ... on User {
36
- ${U(!1,r)}
36
+ ${q(!1,r)}
37
37
  }
38
38
  ... on Bot {
39
- ${ze(!1)}
39
+ ${We(!1)}
40
40
  }
41
41
  }
42
42
  commits(last: 1) {
@@ -96,7 +96,7 @@ updatedAt
96
96
  closedAt
97
97
  assignees(first: 100) {
98
98
  nodes {
99
- ${U(!1,r)}
99
+ ${q(!1,r)}
100
100
  }
101
101
  }
102
102
  reviewRequests(first: 100) {
@@ -104,7 +104,7 @@ reviewRequests(first: 100) {
104
104
  asCodeOwner
105
105
  requestedReviewer {
106
106
  ... on User {
107
- ${U(!1,r)}
107
+ ${q(!1,r)}
108
108
  }
109
109
  }
110
110
  }
@@ -113,7 +113,7 @@ latestReviews(first: 100) {
113
113
  nodes {
114
114
  author {
115
115
  ... on User {
116
- ${U(!1,r)}
116
+ ${q(!1,r)}
117
117
  }
118
118
  }
119
119
  state
@@ -137,10 +137,10 @@ databaseId
137
137
  title
138
138
  author {
139
139
  ... on User {
140
- ${U(!1,e)}
140
+ ${q(!1,e)}
141
141
  }
142
142
  ... on Bot {
143
- ${ze(!1)}
143
+ ${We(!1)}
144
144
  }
145
145
  }
146
146
  createdAt
@@ -161,7 +161,7 @@ comments {
161
161
  }
162
162
  assignees(first: 100) {
163
163
  nodes {
164
- ${U(!1,e)}
164
+ ${q(!1,e)}
165
165
  }
166
166
  }
167
167
  state
@@ -173,7 +173,7 @@ labels(first: 100) {
173
173
  ${ee}
174
174
  }
175
175
  }
176
- `,ft={"-linked":"-linked",archived:"archived",assignee:"assignee",author:"author",base:"base",closed:"closed",commenter:"commenter",comments:"comments",created:"created",draft:"draft",head:"head",label:"label",language:"language",linked:"linked",in:"in",interactions:"interactions",involves:"involves",is:"is",mentions:"mentions",merged:"merged",milestone:"milestone",no:"no",org:"org",project:"project",reactions:"reactions",repo:"repo",review:"review","reviewed-by":"reviewed-by","review-requested":"review-requested",state:"state",status:"status",team:"team","team-review-requested":"team-review-requested",type:"type",updated:"updated",user:"user","user-review-requested":"user-review-requested"},Rt=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),ge=e=>{let r=[];return(e.match(Rt)??[]).forEach(s=>{if(s.includes(":")&&s!="is:closed"){let n=s.split(":")[0];ft[n]&&r.push(s)}}),r},me=(e,r,t,s,n=!1)=>{let a=e==="issue";return{query:`
176
+ `,ft={"-linked":"-linked",archived:"archived",assignee:"assignee",author:"author",base:"base",closed:"closed",commenter:"commenter",comments:"comments",created:"created",draft:"draft",head:"head",label:"label",language:"language",linked:"linked",in:"in",interactions:"interactions",involves:"involves",is:"is",mentions:"mentions",merged:"merged",milestone:"milestone",no:"no",org:"org",project:"project",reactions:"reactions",repo:"repo",review:"review","reviewed-by":"reviewed-by","review-requested":"review-requested",state:"state",status:"status",team:"team","team-review-requested":"team-review-requested",type:"type",updated:"updated",user:"user","user-review-requested":"user-review-requested"},Rt=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),he=e=>{let r=[];return(e.match(Rt)??[]).forEach(s=>{if(s.includes(":")&&s!="is:closed"){let n=s.split(":")[0];ft[n]&&r.push(s)}}),r},fe=(e,r,t,s,n=!1)=>{let a=e==="issue";return{query:`
177
177
  query SearchIssuesOrPullRequests($query: String! $after: String) {
178
178
  search(type:ISSUE query:$query first:100 after:$after) {
179
179
  pageInfo {
@@ -186,7 +186,7 @@ query SearchIssuesOrPullRequests($query: String! $after: String) {
186
186
  }
187
187
  }
188
188
  }
189
- }`,variables:{query:`is:${e} is:open ${r}`,after:t}}},It="Field 'isDraft' doesn't exist on type 'PullRequest'",We=(e=[])=>e.some(r=>(r==null?void 0:r.message)===It);var he=`
189
+ }`,variables:{query:`is:${e} is:open ${r}`,after:t}}},It="Field 'isDraft' doesn't exist on type 'PullRequest'",He=(e=[])=>e.some(r=>(r==null?void 0:r.message)===It);var Re=`
190
190
  id
191
191
  databaseId
192
192
  owner {
@@ -199,13 +199,13 @@ defaultBranchRef {
199
199
  name
200
200
  }
201
201
  viewerPermission
202
- `,Re={__typename:"User",id:"U_kgDNJ5k",databaseId:10137,name:"Deleted user",login:"ghost",email:"",avatarUrl:"https://avatars.githubusercontent.com/u/10137?v=4"},bt={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},yt={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},Pt={OPEN:"OPEN",CLOSED:"CLOSED"},Ie=e=>({color:e.color,description:e.description,graphQLId:e.id,id:null,name:e.name}),fe=e=>({id:e.databaseId.toString(),graphQLId:e.id,namespace:e.owner.login,name:e.name,webUrl:e.url,httpsUrl:e.url.endsWith(".git")?e.url:`${e.url}.git`,sshUrl:e.sshUrl,defaultBranch:e.defaultBranchRef,permission:e.viewerPermission}),wt={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},S=e=>({id:e.databaseId.toString(),graphQLId:e.id,name:e.name??e.login,username:e.login,email:e.email??null,avatarUrl:e.avatarUrl}),Ct=e=>{var l,p,d,c,g,R,I,P,y,b;let r=null;e.author?r=(e.author.__typename==="Bot",e.author):r=Re;let t=(p=(l=e.commits.nodes)==null?void 0:l[0])==null?void 0:p.commit,s=((d=e.headRef)==null?void 0:d.target)||t,n=s==null?void 0:s.oid,a=t==null?void 0:t.oid,o=n===a?(g=(c=t==null?void 0:t.status)==null?void 0:c.contexts)==null?void 0:g[0]:null,i=(((R=e.reviewRequests)==null?void 0:R.nodes)||[]).filter(w=>!w.asCodeOwner),u=(I=e.headRepository)==null?void 0:I.url;return u&&!u.endsWith(".git")&&(u=`${u}.git`),{id:e.databaseId.toString(),graphQLId:e.id,title:e.title,number:e.number,state:wt[e.state],commentCount:e.comments.totalCount,upvoteCount:e.reactions.totalCount,author:r?S(r):null,createdDate:new Date(e.createdAt),isDraft:e.isDraft,repository:{name:e.repository.name,owner:{login:e.repository.owner.login}},headRepository:e.headRepository?{name:e.headRepository.name,owner:{login:e.headRepository.owner.login},remoteInfo:{cloneUrlHTTPS:u,cloneUrlSSH:e.headRepository.sshUrl}}:null,headCommit:{buildStatus:o||null},headRef:e.headRef?{name:e.headRef.name}:null,baseRef:e.baseRef?{name:e.baseRef.name}:null,url:e.url,updatedDate:new Date(e.updatedAt),closedDate:e.closedAt?new Date(e.closedAt):null,assignees:e.assignees.nodes?e.assignees.nodes.map(S):null,reviews:i.map(w=>({reviewer:S(w.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((((P=e.latestReviews)==null?void 0:P.nodes)||[]).map(w=>{let L=w.author||Re;return{reviewer:S(L),state:bt[w.state]}})),additions:e.additions,deletions:e.deletions,fileCount:e.changedFiles,commitCount:e.commits.totalCount,mergeableState:yt[e.mergeable],milestone:e.milestone?be(e.milestone):null,labels:((b=(y=e.labels)==null?void 0:y.nodes)==null?void 0:b.map(Ie))??[]}},vt=e=>{var t,s;let r=null;return e.author?r=(e.author.__typename==="Bot",e.author):r=Re,{id:e.databaseId.toString(),graphQLId:e.id,number:e.number,title:e.title,author:S(r),commentCount:e.comments.totalCount,createdDate:new Date(e.createdAt),description:null,state:{name:Pt[e.state],color:null},type:null,repository:{name:e.repository.name,owner:{login:e.repository.owner.login}},url:e.url,updatedDate:new Date(e.updatedAt),assignees:e.assignees.nodes?e.assignees.nodes.map(S):[],upvoteCount:e.reactions.totalCount,milestone:e.milestone?be(e.milestone):null,labels:((s=(t=e.labels)==null?void 0:t.nodes)==null?void 0:s.map(Ie))??[]}},be=e=>({id:e.number.toString(),graphQLId:e.id.toString(),number:e.number,title:e.title,description:e.description,isOpen:e.state=="OPEN",url:e.url,startDate:null,dueDate:e.dueOn?new Date(e.dueOn):null}),F=class extends x{constructor(){super(...arguments);this._scopesCache={}}async getScopes(t){let s=t.token||this.config.token;if(!s)return[];let n=this._scopesCache[s];if(!n){let o=(await h(this.config,{query:"query { rateLimit(dryRun: true) { __typename } }"},t)).headers["x-oauth-scopes"];n=o?o.split(", "):[],this._scopesCache[s]=n}return n}getEnterpriseAvatarUrlIfNeeded(t,s,n){let a=n.baseUrl||this.config.baseUrl;return!a||a.startsWith(ce)?t:s?`https://avatars.githubusercontent.com/u/e?email=${encodeURIComponent(s)}`:""}async getCurrentUser(t={}){var o;let s=await this.getScopes(t),a=(o=(await h(this.config,{query:`
202
+ `,be={__typename:"User",id:"U_kgDNJ5k",databaseId:10137,name:"Deleted user",login:"ghost",email:"",avatarUrl:"https://avatars.githubusercontent.com/u/10137?v=4"},bt={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},yt={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},Pt={OPEN:"OPEN",CLOSED:"CLOSED"},ye=e=>({color:e.color,description:e.description,graphQLId:e.id,id:null,name:e.name}),Ie=e=>({id:e.databaseId.toString(),graphQLId:e.id,namespace:e.owner.login,name:e.name,webUrl:e.url,httpsUrl:e.url.endsWith(".git")?e.url:`${e.url}.git`,sshUrl:e.sshUrl,defaultBranch:e.defaultBranchRef,permission:e.viewerPermission}),wt={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},G=e=>({id:e.databaseId.toString(),graphQLId:e.id,name:e.name??e.login,username:e.login,email:e.email??null,avatarUrl:e.avatarUrl}),Ct=e=>{var l,p,d,c,g,R,I,P,y,b,v,L;let r=null;e.author?r=(e.author.__typename==="Bot",e.author):r=be;let t=(p=(l=e.commits.nodes)==null?void 0:l[0])==null?void 0:p.commit,s=((d=e.headRef)==null?void 0:d.target)||t,n=s==null?void 0:s.oid,a=t==null?void 0:t.oid,o=n===a?(g=(c=t==null?void 0:t.status)==null?void 0:c.contexts)==null?void 0:g[0]:null,i=(((R=e.reviewRequests)==null?void 0:R.nodes)||[]).filter(D=>!D.asCodeOwner),u=(I=e.headRepository)==null?void 0:I.url;return u&&!u.endsWith(".git")&&(u=`${u}.git`),{id:e.databaseId.toString(),graphQLId:e.id,title:e.title,number:e.number,state:wt[e.state],commentCount:e.comments.totalCount,upvoteCount:e.reactions.totalCount,author:r?G(r):null,createdDate:new Date(e.createdAt),isDraft:e.isDraft,repository:{name:e.repository.name,owner:{login:e.repository.owner.login}},headRepository:e.headRepository?{name:e.headRepository.name,owner:{login:e.headRepository.owner.login},remoteInfo:{cloneUrlHTTPS:u,cloneUrlSSH:e.headRepository.sshUrl}}:null,headCommit:{buildStatus:o||null},headRef:e.headRef?{name:e.headRef.name,oid:((P=e.headRef.target)==null?void 0:P.oid)??null}:null,baseRef:e.baseRef?{name:e.baseRef.name,oid:((y=e.baseRef.target)==null?void 0:y.oid)??null}:null,url:e.url,updatedDate:new Date(e.updatedAt),closedDate:e.closedAt?new Date(e.closedAt):null,assignees:e.assignees.nodes?e.assignees.nodes.map(G):null,reviews:i.map(D=>({reviewer:G(D.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((((b=e.latestReviews)==null?void 0:b.nodes)||[]).map(D=>{let ue=D.author||be;return{reviewer:G(ue),state:bt[D.state]}})),additions:e.additions,deletions:e.deletions,fileCount:e.changedFiles,commitCount:e.commits.totalCount,mergeableState:yt[e.mergeable],milestone:e.milestone?Pe(e.milestone):null,labels:((L=(v=e.labels)==null?void 0:v.nodes)==null?void 0:L.map(ye))??[]}},vt=e=>{var t,s;let r=null;return e.author?r=(e.author.__typename==="Bot",e.author):r=be,{id:e.databaseId.toString(),graphQLId:e.id,number:e.number,title:e.title,author:G(r),commentCount:e.comments.totalCount,createdDate:new Date(e.createdAt),description:null,state:{name:Pt[e.state],color:null},type:null,repository:{name:e.repository.name,owner:{login:e.repository.owner.login}},url:e.url,updatedDate:new Date(e.updatedAt),assignees:e.assignees.nodes?e.assignees.nodes.map(G):[],upvoteCount:e.reactions.totalCount,milestone:e.milestone?Pe(e.milestone):null,labels:((s=(t=e.labels)==null?void 0:t.nodes)==null?void 0:s.map(ye))??[]}},Pe=e=>({id:e.number.toString(),graphQLId:e.id.toString(),number:e.number,title:e.title,description:e.description,isOpen:e.state=="OPEN",url:e.url,startDate:null,dueDate:e.dueOn?new Date(e.dueOn):null}),M=class extends T{constructor(){super(...arguments);this._scopesCache={}}async getScopes(t){let s=t.token||this.config.token;if(!s)return[];let n=this._scopesCache[s];if(!n){let o=(await h(this.config,{query:"query { rateLimit(dryRun: true) { __typename } }"},t)).headers["x-oauth-scopes"];n=o?o.split(", "):[],this._scopesCache[s]=n}return n}getEnterpriseAvatarUrlIfNeeded(t,s,n){let a=n.baseUrl||this.config.baseUrl;return!a||a.startsWith(me)?t:s?`https://avatars.githubusercontent.com/u/e?email=${encodeURIComponent(s)}`:""}async getCurrentUser(t={}){var o;let s=await this.getScopes(t),a=(o=(await h(this.config,{query:`
203
203
  query getCurrentUser {
204
204
  viewer {
205
- ${U(!1,O(s))}
205
+ ${q(!1,k(s))}
206
206
  }
207
207
  }
208
- `},t)).body.data)==null?void 0:o.viewer;if(!a)throw new Error("Current user not found.");return{data:S(a)}}async getUserForCommit(t,s={}){var i,u;let a=(i=(await h(this.config,{query:`
208
+ `},t)).body.data)==null?void 0:o.viewer;if(!a)throw new Error("Current user not found.");return{data:G(a)}}async getUserForCommit(t,s={}){var i,u;let a=(i=(await h(this.config,{query:`
209
209
  query getUserForCommit(
210
210
  $owner: String!
211
211
  $name: String!
@@ -229,18 +229,18 @@ query getAccountForEmail($query: String! $avatarSize: Int) {
229
229
  search(query: $query, type: USER, first: 1) {
230
230
  nodes {
231
231
  ... on User {
232
- ${U(!0,O(n))}
232
+ ${q(!0,k(n))}
233
233
  }
234
234
  }
235
235
  }
236
236
  }
237
- `,variables:{query:`in:email ${t.email}`,avatarSize:t.avatarSize}},s)).body.data)==null?void 0:i.search)==null?void 0:u.nodes)==null?void 0:l[0];if(!o)throw new Error("User not found.");return{data:S({...o,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(o.avatarUrl,o.email,s)})}}async getAccountForUsername(t,s={}){var i;let n=await this.getScopes(s),o=(i=(await h(this.config,{query:`
237
+ `,variables:{query:`in:email ${t.email}`,avatarSize:t.avatarSize}},s)).body.data)==null?void 0:i.search)==null?void 0:u.nodes)==null?void 0:l[0];if(!o)throw new Error("User not found.");return{data:G({...o,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(o.avatarUrl,o.email,s)})}}async getAccountForUsername(t,s={}){var i;let n=await this.getScopes(s),o=(i=(await h(this.config,{query:`
238
238
  query getUserForUsername($login: String! $avatarSize: Int) {
239
239
  user(login: $login) {
240
- ${U(!0,O(n))}
240
+ ${q(!0,k(n))}
241
241
  }
242
242
  }
243
- `,variables:{login:t.username,avatarSize:t.avatarSize}},s)).body.data)==null?void 0:i.user;if(!o)throw new Error("User not found.");return{data:S({...o,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(o.avatarUrl,o.email,s)})}}async getOrgsForCurrentUser(t={},s={}){var o,i;let n=await h(this.config,{query:`
243
+ `,variables:{login:t.username,avatarSize:t.avatarSize}},s)).body.data)==null?void 0:i.user;if(!o)throw new Error("User not found.");return{data:G({...o,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(o.avatarUrl,o.email,s)})}}async getOrgsForCurrentUser(t={},s={}){var o,i;let n=await h(this.config,{query:`
244
244
  query getOrgsForCurrentUser($cursor: String, $first: Int!) {
245
245
  viewer {
246
246
  organizations(first: $first after: $cursor) {
@@ -259,22 +259,22 @@ query getOrgsForCurrentUser($cursor: String, $first: Int!) {
259
259
  }
260
260
  }
261
261
  }
262
- `,variables:{cursor:t.cursor,first:v}},s);if(!((o=n.body.data)!=null&&o.viewer.organizations))throw new Error(((i=n.body.errors)==null?void 0:i[0].message)||n.statusText||"Unknown error");let a=n.body.data.viewer.organizations.nodes||[];return{pageInfo:n.body.data.viewer.organizations.pageInfo,data:a.map(u=>({id:u.databaseId.toString(),graphQLId:u.id,username:u.login,name:u.name||null,email:u.email||null,avatarUrl:u.avatarUrl}))}}async getRepo(t,s={}){var a;let n=await h(this.config,{query:`
262
+ `,variables:{cursor:t.cursor,first:C}},s);if(!((o=n.body.data)!=null&&o.viewer.organizations))throw new Error(((i=n.body.errors)==null?void 0:i[0].message)||n.statusText||"Unknown error");let a=n.body.data.viewer.organizations.nodes||[];return{pageInfo:n.body.data.viewer.organizations.pageInfo,data:a.map(u=>({id:u.databaseId.toString(),graphQLId:u.id,username:u.login,name:u.name||null,email:u.email||null,avatarUrl:u.avatarUrl}))}}async getRepo(t,s={}){var a;let n=await h(this.config,{query:`
263
263
  query getRepo($owner: String!, $name: String!) {
264
264
  repository(owner: $owner, name: $name) {
265
- ${he}
265
+ ${Re}
266
266
  }
267
267
  }
268
- `,variables:{owner:t.namespace,name:t.name}},s);if(!((a=n.body.data)!=null&&a.repository))throw new Error(`Repository ${t.namespace}/${t.name} not found`);return{data:fe(n.body.data.repository)}}async getRepos(t,s={}){let n=t.map(({namespace:u,name:l},p)=>`
268
+ `,variables:{owner:t.namespace,name:t.name}},s);if(!((a=n.body.data)!=null&&a.repository))throw new Error(`Repository ${t.namespace}/${t.name} not found`);return{data:Ie(n.body.data.repository)}}async getRepos(t,s={}){let n=t.map(({namespace:u,name:l},p)=>`
269
269
  getRepo_${p}: repository(owner: "${u}", name: "${l}") {
270
- ${he}
270
+ ${Re}
271
271
  }
272
272
  `).join(`
273
273
  `),a=await h(this.config,{query:`
274
274
  query batchGetRepos {
275
275
  ${n}
276
276
  }
277
- `},s);if(!a.body.data)throw new Error(a.statusText||"Unknown error");let o=[],i=[];return t.forEach((u,l)=>{let p=a.body.data[`getRepo_${l}`];p?o.push(fe(p)):i.push({input:u})}),{data:o,errors:i}}async getReposForUsernames(t,s={}){var o;if(!t.usernames.length)return{pageInfo:{endCursor:null,hasNextPage:!1},data:[]};let n=await h(this.config,{query:`
277
+ `},s);if(!a.body.data)throw new Error(a.statusText||"Unknown error");let o=[],i=[];return t.forEach((u,l)=>{let p=a.body.data[`getRepo_${l}`];p?o.push(Ie(p)):i.push({input:u})}),{data:o,errors:i}}async getReposForUsernames(t,s={}){var o;if(!t.usernames.length)return{pageInfo:{endCursor:null,hasNextPage:!1},data:[]};let n=await h(this.config,{query:`
278
278
  query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
279
279
  search(query: $query, type: REPOSITORY, first: $first, after: $cursor) {
280
280
  pageInfo {
@@ -283,12 +283,12 @@ query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
283
283
  }
284
284
  nodes {
285
285
  ... on Repository {
286
- ${he}
286
+ ${Re}
287
287
  }
288
288
  }
289
289
  }
290
290
  }
291
- `,variables:{query:`fork:true ${t.usernames.map(i=>`user:${i}`).join(" ")}`,cursor:t.cursor,first:v}},s);if(!n.body.data)throw new Error(((o=n.body.errors)==null?void 0:o[0].message)||n.statusText||"Unknown error");let a=n.body.data.search.nodes||[];return{pageInfo:n.body.data.search.pageInfo,data:a.map(fe)}}async getReposForOwners(t,s={}){return this.getReposForUsernames({usernames:t.owners.filter(n=>n.username).map(n=>n.username),cursor:t.cursor},s)}async getRefs(t,s,n={}){var u;let o=(u=(await h(this.config,{query:`
291
+ `,variables:{query:`fork:true ${t.usernames.map(i=>`user:${i}`).join(" ")}`,cursor:t.cursor,first:C}},s);if(!n.body.data)throw new Error(((o=n.body.errors)==null?void 0:o[0].message)||n.statusText||"Unknown error");let a=n.body.data.search.nodes||[];return{pageInfo:n.body.data.search.pageInfo,data:a.map(Ie)}}async getReposForOwners(t,s={}){return this.getReposForUsernames({usernames:t.owners.filter(n=>n.username).map(n=>n.username),cursor:t.cursor},s)}async getRefs(t,s,n={}){var u;let o=(u=(await h(this.config,{query:`
292
292
  query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: String, $first: Int!) {
293
293
  repository(owner: $owner, name: $name) {
294
294
  refs(refPrefix: $refPrefix first: $first after: $cursor) {
@@ -309,7 +309,7 @@ query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: Str
309
309
  }
310
310
  }
311
311
  }
312
- `,variables:{owner:s.repo.namespace,name:s.repo.name,refPrefix:t,cursor:s.cursor,first:v}},n)).body.data)==null?void 0:u.repository;if(!o)throw new Error("Repository not found.");let i=o.refs;return i?{pageInfo:i.pageInfo,data:(i.nodes||[]).map(l=>{var d;let p=(d=l.target)!=null&&d.oid?l.target:null;return{name:l.name,commit:p?{oid:p.oid,authoredDate:new Date(p.authoredDate),committedDate:new Date(p.committedDate)}:null}})}:{pageInfo:{endCursor:null,hasNextPage:!1},data:[]}}async getBranches(t,s={}){return this.getRefs("refs/heads/",t,s)}async getTags(t,s={}){return this.getRefs("refs/tags/",t,s)}async getBlame(t,s={}){var i;let a=(i=(await h(this.config,{query:`
312
+ `,variables:{owner:s.repo.namespace,name:s.repo.name,refPrefix:t,cursor:s.cursor,first:C}},n)).body.data)==null?void 0:u.repository;if(!o)throw new Error("Repository not found.");let i=o.refs;return i?{pageInfo:i.pageInfo,data:(i.nodes||[]).map(l=>{var d;let p=(d=l.target)!=null&&d.oid?l.target:null;return{name:l.name,commit:p?{oid:p.oid,authoredDate:new Date(p.authoredDate),committedDate:new Date(p.committedDate)}:null}})}:{pageInfo:{endCursor:null,hasNextPage:!1},data:[]}}async getBranches(t,s={}){return this.getRefs("refs/heads/",t,s)}async getTags(t,s={}){return this.getRefs("refs/tags/",t,s)}async getBlame(t,s={}){var i;let a=(i=(await h(this.config,{query:`
313
313
  query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
314
314
  repository(owner: $owner, name: $name) {
315
315
  object(expression: $ref) {
@@ -348,7 +348,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
348
348
  }
349
349
  }
350
350
  }
351
- `,variables:{owner:t.repo.namespace,name:t.repo.name,ref:t.ref,path:t.path}},s)).body.data)==null?void 0:i.repository;if(!a)throw new Error("Repository not found.");let o=a.object;if(!o||!("blame"in o))throw new Error("Ref not found.");if(o.blame.ranges.length===0)throw new Error("File not found.");return{data:{ranges:o.blame.ranges.map(u=>{var l;return{startingLine:u.startingLine,endingLine:u.endingLine,commit:{oid:u.commit.oid,parentOids:((l=u.commit.parents.nodes)==null?void 0:l.map(p=>p.oid))||[],authoredDate:new Date(u.commit.authoredDate),author:u.commit.author?{name:u.commit.author.name,email:u.commit.author.email,avatarUrl:u.commit.author.avatarUrl}:null,committedDate:new Date(u.commit.committedDate),committer:u.commit.committer?{name:u.commit.committer.name,email:u.commit.committer.email,avatarUrl:u.commit.committer.avatarUrl}:null,message:u.commit.message,fileCount:u.commit.changedFilesIfAvailable,additions:u.commit.additions,deletions:u.commit.deletions}}})}}}async searchPullRequests(t,s={}){var l,p;let n=await this.getScopes(s),a=O(n),o=d=>{let c=d&&typeof t.isDraft=="boolean"?`${t.query} draft:${t.isDraft}`:t.query;return me("pr",c,t.cursor,a,d)},i=await h(this.config,o(!0),s);i.body.errors&&We(i.body.errors)&&(this.config.baseUrl||s.baseUrl)&&(i=await h(this.config,o(!1),s));let{data:u}=i.body;if(!u)throw new Error(((l=i.body.errors)==null?void 0:l[0].message)||i.statusText||"Unknown error");return{pageInfo:{hasNextPage:u.search.pageInfo.hasNextPage,endCursor:u.search.pageInfo.endCursor},data:((p=u.search.nodes)==null?void 0:p.map(Ct))||[]}}async searchIssues(t,s={}){var u,l;let n=await this.getScopes(s),a=O(n),o=await h(this.config,me("issue",t.query,t.cursor,a),s),{data:i}=o.body;if(!i)throw new Error(((u=o.body.errors)==null?void 0:u[0].message)||o.statusText||"Unknown error");return{pageInfo:{hasNextPage:i.search.pageInfo.hasNextPage,endCursor:i.search.pageInfo.endCursor},data:((l=i.search.nodes)==null?void 0:l.map(vt))||[]}}async getPullRequestsAssociatedWithUser(t,s={}){var g;let[n,a,o]=((g=t.cursor)==null?void 0:g.split(";"))||[void 0,void 0,void 0];if(t.cursor&&n==="null"&&a==="null"&&o==="null")return{pageInfo:{hasNextPage:!1,endCursor:"null;null;null"},data:[]};let[i,u,l]=await Promise.all([this.searchPullRequests({query:`author:${t.username}`,cursor:n},s),this.searchPullRequests({query:`assignee:${t.username}`,cursor:a},s),this.searchPullRequests({query:`review-requested:${t.username}`,cursor:o},s)]),p={},d=[],c=R=>{p[R.id]||(p[R.id]=!0,d.push(R))};return i.data.forEach(c),u.data.forEach(c),l.data.forEach(c),{pageInfo:{hasNextPage:i.pageInfo.hasNextPage||u.pageInfo.hasNextPage||l.pageInfo.hasNextPage,endCursor:`${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"};${(l==null?void 0:l.pageInfo.hasNextPage)&&(l==null?void 0:l.pageInfo.endCursor)||"null"}`},data:d}}async getPullRequestsForRepos(t,s={}){let{assigneeLogins:n,updatedBefore:a,authorLogin:o,repos:i,reviewRequestedLogin:u,startQuery:l,mentionLogin:p}=t,d=ge(l||"");return i.forEach(c=>{d.push(`repo:${c.namespace}/${c.name}`)}),n&&n.forEach(c=>{d.push(`assignee:${c}`)}),a&&d.push(`updated:<${a}`),o&&d.push(`author:${o}`),u&&d.push(`review-requested:${u}`),p&&d.push(`mentions:${p}`),this.searchPullRequests({query:`sort:updated ${d.join(" ")}`,isDraft:t.isDraft,cursor:t.cursor},s)}async closePullRequest(t,s={}){var i,u,l;let{pullRequestGraphQLId:n}=t,a=`mutation ClosePullRequest($pullRequestGraphQLId: ID!) {
351
+ `,variables:{owner:t.repo.namespace,name:t.repo.name,ref:t.ref,path:t.path}},s)).body.data)==null?void 0:i.repository;if(!a)throw new Error("Repository not found.");let o=a.object;if(!o||!("blame"in o))throw new Error("Ref not found.");if(o.blame.ranges.length===0)throw new Error("File not found.");return{data:{ranges:o.blame.ranges.map(u=>{var l;return{startingLine:u.startingLine,endingLine:u.endingLine,commit:{oid:u.commit.oid,parentOids:((l=u.commit.parents.nodes)==null?void 0:l.map(p=>p.oid))||[],authoredDate:new Date(u.commit.authoredDate),author:u.commit.author?{name:u.commit.author.name,email:u.commit.author.email,avatarUrl:u.commit.author.avatarUrl}:null,committedDate:new Date(u.commit.committedDate),committer:u.commit.committer?{name:u.commit.committer.name,email:u.commit.committer.email,avatarUrl:u.commit.committer.avatarUrl}:null,message:u.commit.message,fileCount:u.commit.changedFilesIfAvailable,additions:u.commit.additions,deletions:u.commit.deletions}}})}}}async searchPullRequests(t,s={}){var l,p;let n=await this.getScopes(s),a=k(n),o=d=>{let c=d&&typeof t.isDraft=="boolean"?`${t.query} draft:${t.isDraft}`:t.query;return fe("pr",c,t.cursor,a,d)},i=await h(this.config,o(!0),s);i.body.errors&&He(i.body.errors)&&(this.config.baseUrl||s.baseUrl)&&(i=await h(this.config,o(!1),s));let{data:u}=i.body;if(!u)throw new Error(((l=i.body.errors)==null?void 0:l[0].message)||i.statusText||"Unknown error");return{pageInfo:{hasNextPage:u.search.pageInfo.hasNextPage,endCursor:u.search.pageInfo.endCursor},data:((p=u.search.nodes)==null?void 0:p.map(Ct))||[]}}async searchIssues(t,s={}){var u,l;let n=await this.getScopes(s),a=k(n),o=await h(this.config,fe("issue",t.query,t.cursor,a),s),{data:i}=o.body;if(!i)throw new Error(((u=o.body.errors)==null?void 0:u[0].message)||o.statusText||"Unknown error");return{pageInfo:{hasNextPage:i.search.pageInfo.hasNextPage,endCursor:i.search.pageInfo.endCursor},data:((l=i.search.nodes)==null?void 0:l.map(vt))||[]}}async getPullRequestsAssociatedWithUser(t,s={}){var g;let[n,a,o]=((g=t.cursor)==null?void 0:g.split(";"))||[void 0,void 0,void 0];if(t.cursor&&n==="null"&&a==="null"&&o==="null")return{pageInfo:{hasNextPage:!1,endCursor:"null;null;null"},data:[]};let[i,u,l]=await Promise.all([this.searchPullRequests({query:`author:${t.username}`,cursor:n},s),this.searchPullRequests({query:`assignee:${t.username}`,cursor:a},s),this.searchPullRequests({query:`review-requested:${t.username}`,cursor:o},s)]),p={},d=[],c=R=>{p[R.id]||(p[R.id]=!0,d.push(R))};return i.data.forEach(c),u.data.forEach(c),l.data.forEach(c),{pageInfo:{hasNextPage:i.pageInfo.hasNextPage||u.pageInfo.hasNextPage||l.pageInfo.hasNextPage,endCursor:`${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"};${(l==null?void 0:l.pageInfo.hasNextPage)&&(l==null?void 0:l.pageInfo.endCursor)||"null"}`},data:d}}async getPullRequestsForRepos(t,s={}){let{assigneeLogins:n,updatedBefore:a,authorLogin:o,repos:i,reviewRequestedLogin:u,startQuery:l,mentionLogin:p}=t,d=he(l||"");return i.forEach(c=>{d.push(`repo:${c.namespace}/${c.name}`)}),n&&n.forEach(c=>{d.push(`assignee:${c}`)}),a&&d.push(`updated:<${a}`),o&&d.push(`author:${o}`),u&&d.push(`review-requested:${u}`),p&&d.push(`mentions:${p}`),this.searchPullRequests({query:`sort:updated ${d.join(" ")}`,isDraft:t.isDraft,cursor:t.cursor},s)}async closePullRequest(t,s={}){var i,u,l;let{pullRequestGraphQLId:n}=t,a=`mutation ClosePullRequest($pullRequestGraphQLId: ID!) {
352
352
  closePullRequest(input: { pullRequestId: $pullRequestGraphQLId }) {
353
353
  pullRequest {
354
354
  id
@@ -378,7 +378,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
378
378
  id
379
379
  }
380
380
  }
381
- }`;if(!((u=(i=(o=(await h(this.config,{query:n,variables:{pullRequestGraphQLId:t}},s)).body.data)==null?void 0:o.convertPullRequestToDraft)==null?void 0:i.pullRequest)!=null&&u.id))throw new Error("Could not convert pull request to draft")}async setPullRequestAsDraft(t,s={}){let{pullRequestGraphQLId:n,isDraft:a}=t;if(a){await this.convertPullRequestToDraft(n,s);return}await this.markPullRequestReadyForReview(n,s)}async getIssuesAssociatedWithUser(t,s={}){var d;let[n,a]=((d=t.cursor)==null?void 0:d.split(";"))||[void 0,void 0];if(t.cursor&&n==="null"&&a==="null")return{pageInfo:{hasNextPage:!1,endCursor:"null;null"},data:[]};let[o,i]=await Promise.all([this.searchIssues({query:`author:${t.username}`,cursor:n},s),this.searchIssues({query:`assignee:${t.username}`,cursor:a},s)]),u={},l=[],p=c=>{u[c.id]||(u[c.id]=!0,l.push(c))};return o.data.forEach(p),i.data.forEach(p),{pageInfo:{hasNextPage:o.pageInfo.hasNextPage||i.pageInfo.hasNextPage,endCursor:`${(o==null?void 0:o.pageInfo.hasNextPage)&&(o==null?void 0:o.pageInfo.endCursor)||"null"};${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"}`},data:l}}async getIssuesForRepos(t,s={}){let n=ge(t.startQuery||""),{cursor:a,assigneeLogins:o,updatedBefore:i,authorLogin:u,mentionLogin:l}=t;return t.repos.forEach(p=>{n.push(`repo:${p.namespace}/${p.name}`)}),o&&o.forEach(p=>{n.push(`assignee:${p}`)}),i&&n.push(`updated:<${i}`),u&&n.push(`author:${u}`),l&&n.push(`mentions:${l}`),this.searchIssues({query:`sort:updated ${n.join(" ")}`,cursor:a},s)}async closeIssueWithReason(t,s,n){var i,u,l;let a=`mutation CloseIssueWithReason($issueGraphQLId: ID!, $closeReason: IssueClosedStateReason!) {
381
+ }`;if(!((u=(i=(o=(await h(this.config,{query:n,variables:{pullRequestGraphQLId:t}},s)).body.data)==null?void 0:o.convertPullRequestToDraft)==null?void 0:i.pullRequest)!=null&&u.id))throw new Error("Could not convert pull request to draft")}async setPullRequestAsDraft(t,s={}){let{pullRequestGraphQLId:n,isDraft:a}=t;if(a){await this.convertPullRequestToDraft(n,s);return}await this.markPullRequestReadyForReview(n,s)}async getIssuesAssociatedWithUser(t,s={}){var d;let[n,a]=((d=t.cursor)==null?void 0:d.split(";"))||[void 0,void 0];if(t.cursor&&n==="null"&&a==="null")return{pageInfo:{hasNextPage:!1,endCursor:"null;null"},data:[]};let[o,i]=await Promise.all([this.searchIssues({query:`author:${t.username}`,cursor:n},s),this.searchIssues({query:`assignee:${t.username}`,cursor:a},s)]),u={},l=[],p=c=>{u[c.id]||(u[c.id]=!0,l.push(c))};return o.data.forEach(p),i.data.forEach(p),{pageInfo:{hasNextPage:o.pageInfo.hasNextPage||i.pageInfo.hasNextPage,endCursor:`${(o==null?void 0:o.pageInfo.hasNextPage)&&(o==null?void 0:o.pageInfo.endCursor)||"null"};${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"}`},data:l}}async getIssuesForRepos(t,s={}){let n=he(t.startQuery||""),{cursor:a,assigneeLogins:o,updatedBefore:i,authorLogin:u,mentionLogin:l}=t;return t.repos.forEach(p=>{n.push(`repo:${p.namespace}/${p.name}`)}),o&&o.forEach(p=>{n.push(`assignee:${p}`)}),i&&n.push(`updated:<${i}`),u&&n.push(`author:${u}`),l&&n.push(`mentions:${l}`),this.searchIssues({query:`sort:updated ${n.join(" ")}`,cursor:a},s)}async closeIssueWithReason(t,s,n){var i,u,l;let a=`mutation CloseIssueWithReason($issueGraphQLId: ID!, $closeReason: IssueClosedStateReason!) {
382
382
  closeIssue(input: { issueId: $issueGraphQLId, stateReason: $closeReason }) {
383
383
  issue {
384
384
  id
@@ -416,7 +416,7 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
416
416
  }
417
417
  }
418
418
  }
419
- `,variables:{owner:n,name:a,cursor:o,first:v}},s);if(!i.body.data)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:((l=i.body.data.repository.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=i.body.data.repository.milestones)==null?void 0:p.nodes)==null?void 0:d.map(be))??[]}}async getLabelsForRepo(t,s={}){var u,l,p,d;let{repo:{namespace:n,name:a},cursor:o}=t,i=await h(this.config,{query:`
419
+ `,variables:{owner:n,name:a,cursor:o,first:C}},s);if(!i.body.data)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:((l=i.body.data.repository.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=i.body.data.repository.milestones)==null?void 0:p.nodes)==null?void 0:d.map(Pe))??[]}}async getLabelsForRepo(t,s={}){var u,l,p,d;let{repo:{namespace:n,name:a},cursor:o}=t,i=await h(this.config,{query:`
420
420
  query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
421
421
  repository(owner: $owner, name: $name) {
422
422
  labels(first: $first, after: $cursor) {
@@ -430,7 +430,7 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
430
430
  }
431
431
  }
432
432
  }
433
- `,variables:{owner:n,name:a,cursor:o,first:v}},s);if(!i.body.data)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:((l=i.body.data.repository.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=i.body.data.repository.labels)==null?void 0:p.nodes)==null?void 0:d.map(Ie))??[]}}};var Et="https://gitlab.com/api/v4",$t="https://gitlab.com/api/graphql",He=/\/api\/v\d+$/,Je=e=>{if(e.endsWith("/api/graphql"))throw new Error("The graphql endpoint is being used as the baseUrl. This package uses both GraphQL and REST APIs, and the REST version cannot be assumed. Use the REST endpoint as the baseUrl instead.")},ye=(e,r)=>{let t=r.baseUrl||e.baseUrl;return t?(t=t.replace(/\/$/,""),Je(t),t):Et},Dt=(e,r)=>{let t=r.baseUrl||e.baseUrl;return t?(t=t.replace(/\/$/,""),Je(t),He.test(t)&&(t=t.replace(He,"")),`${t}/api/graphql`):$t},f=(e,r,t)=>{let s=m(t.token||e.token);return e.request({url:Dt(e,t),method:"POST",headers:{...s,"Content-Type":"application/json"},body:JSON.stringify(r)})};var Ve=e=>e.split("/").slice(0,-1).join("/"),k=e=>({namespace:Ve(e.fullPath),name:e.path,webUrl:e.webUrl}),Ut={assigned:"assignedMergeRequests",authored:"authoredMergeRequests",reviewRequested:"reviewRequestedMergeRequests"},qt={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"},De="gid://gitlab/User/",M="gid://gitlab/Project/",St="gid://gitlab/MergeRequest/",Lt="gid://gitlab/Issue/",Gt="gid://gitlab/ProjectLabel/",Ke="gid://gitlab/Milestone/",Ue=`
433
+ `,variables:{owner:n,name:a,cursor:o,first:C}},s);if(!i.body.data)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:((l=i.body.data.repository.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=i.body.data.repository.labels)==null?void 0:p.nodes)==null?void 0:d.map(ye))??[]}}};var $t="https://gitlab.com/api/v4",Dt="https://gitlab.com/api/graphql",Je=/\/api\/v\d+$/,Ve=e=>{if(e.endsWith("/api/graphql"))throw new Error("The graphql endpoint is being used as the baseUrl. This package uses both GraphQL and REST APIs, and the REST version cannot be assumed. Use the REST endpoint as the baseUrl instead.")},we=(e,r)=>{let t=r.baseUrl||e.baseUrl;return t?(t=t.replace(/\/$/,""),Ve(t),t):$t},Et=(e,r)=>{let t=r.baseUrl||e.baseUrl;return t?(t=t.replace(/\/$/,""),Ve(t),Je.test(t)&&(t=t.replace(Je,"")),`${t}/api/graphql`):Dt},f=(e,r,t)=>{let s=m(t.token||e.token);return e.request({url:Et(e,t),method:"POST",headers:{...s,"Content-Type":"application/json"},body:JSON.stringify(r)})};var Ke=e=>e.split("/").slice(0,-1).join("/"),_=e=>({namespace:Ke(e.fullPath),name:e.path,webUrl:e.webUrl}),St={assigned:"assignedMergeRequests",authored:"authoredMergeRequests",reviewRequested:"reviewRequestedMergeRequests"},Ut={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"},Ue="gid://gitlab/User/",z="gid://gitlab/Project/",qt="gid://gitlab/MergeRequest/",Lt="gid://gitlab/Issue/",Gt="gid://gitlab/ProjectLabel/",Xe="gid://gitlab/Milestone/",qe=`
434
434
  description
435
435
  dueDate
436
436
  id
@@ -439,7 +439,7 @@ startDate
439
439
  state
440
440
  title
441
441
  webPath
442
- `,Pe=`
442
+ `,Ce=`
443
443
  id
444
444
  path
445
445
  fullPath
@@ -449,24 +449,24 @@ sshUrlToRepo
449
449
  repository {
450
450
  rootRef
451
451
  }
452
- `,T=`
452
+ `,A=`
453
453
  id
454
454
  name
455
455
  username
456
456
  publicEmail
457
457
  avatarUrl
458
- `,qe=`
458
+ `,Le=`
459
459
  color
460
460
  description
461
461
  id
462
462
  title
463
- `,we=`
463
+ `,ve=`
464
464
  author {
465
- ${T}
465
+ ${A}
466
466
  }
467
467
  assignees {
468
468
  nodes {
469
- ${T}
469
+ ${A}
470
470
  }
471
471
  }
472
472
  createdAt
@@ -476,7 +476,7 @@ id
476
476
  iid
477
477
  labels {
478
478
  nodes {
479
- ${qe}
479
+ ${Le}
480
480
  }
481
481
  }
482
482
  state
@@ -487,13 +487,17 @@ upvotes
487
487
  userNotesCount
488
488
  webUrl
489
489
  milestone {
490
- ${Ue}
490
+ ${qe}
491
491
  }
492
- `,Ce=(e,r)=>`
492
+ `,$e=(e,r)=>`
493
493
  id
494
494
  state
495
495
  author {
496
- ${T}
496
+ ${A}
497
+ }
498
+ diffRefs {
499
+ baseSha
500
+ headSha
497
501
  }
498
502
  diffStatsSummary {
499
503
  additions
@@ -514,12 +518,12 @@ targetBranch
514
518
  sourceBranch
515
519
  assignees {
516
520
  nodes {
517
- ${T}
521
+ ${A}
518
522
  }
519
523
  }
520
524
  reviewers {
521
525
  nodes {
522
- ${T}
526
+ ${A}
523
527
  mergeRequestInteraction {
524
528
  approved
525
529
  reviewState
@@ -529,18 +533,18 @@ reviewers {
529
533
  mergeStatusEnum
530
534
  labels {
531
535
  nodes {
532
- ${qe}
536
+ ${Le}
533
537
  }
534
538
  }
535
539
  ${e?"project { path fullPath webUrl }":""}
536
- ${r?`milestone { ${Ue} }`:""}
537
- `,A=e=>`${e.namespace}/${e.name}`,xt=e=>`${e.namespace}/${e.name}`,ve=e=>{var r;return{id:e.id.replace(M,""),graphQLId:e.id,namespace:Ve(e.fullPath),name:e.path,webUrl:e.webUrl,httpsUrl:e.httpUrlToRepo,sshUrl:e.sshUrlToRepo,defaultBranch:(r=e.repository)!=null&&r.rootRef?{name:e.repository.rootRef}:null,permission:null}},Tt={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},_=e=>({id:e.id.replace(De,""),graphQLId:e.id,name:e.name,username:e.username,email:e.publicEmail,avatarUrl:e.avatarUrl}),Se=e=>({color:e.color,description:e.description,id:e.id.replace(Gt,""),graphQLId:e.id,name:e.title}),Ee=(e,r)=>{var t,s,n,a,o,i,u;return{id:e.id.replace(St,""),graphQLId:e.id,title:e.title,number:parseInt(e.iid,10),state:Tt[e.state],commentCount:e.userNotesCount||0,upvoteCount:e.upvotes,author:e.author?_(e.author):null,createdDate:new Date(e.createdAt),isDraft:e.draft,repository:{name:r.name,owner:{login:r.namespace}},headRepository:null,headCommit:{buildStatus:null},baseRef:{name:e.targetBranch},headRef:{name:e.sourceBranch},url:e.webUrl,updatedDate:new Date(e.updatedAt),closedDate:e.mergedAt?new Date(e.mergedAt):null,assignees:(t=e.assignees)!=null&&t.nodes?e.assignees.nodes.map(_):null,reviews:(s=e.reviewers)!=null&&s.nodes?e.reviewers.nodes.map(l=>{var p,d;return{reviewer:_(l),state:(p=l.mergeRequestInteraction)!=null&&p.approved?"APPROVED":((d=l.mergeRequestInteraction)==null?void 0:d.reviewState)==="REVIEWED"?"CHANGES_REQUESTED":"CHANGES_REQUESTED"}}):null,additions:((n=e.diffStatsSummary)==null?void 0:n.additions)||0,deletions:((a=e.diffStatsSummary)==null?void 0:a.deletions)||0,fileCount:((o=e.diffStatsSummary)==null?void 0:o.fileCount)||0,commitCount:e.commitCount||0,mergeableState:qt[e.mergeStatusEnum],milestone:e.milestone?Le(e.milestone,r.webUrl):null,labels:((u=(i=e.labels)==null?void 0:i.nodes)==null?void 0:u.map(Se))??[]}},$e=(e,r)=>{var t,s;return{author:{avatarUrl:e.author.avatarUrl,email:null,graphQLId:e.author.id,id:e.author.id.replace(De,""),name:e.author.name,username:e.author.username},assignees:e.assignees.nodes.map(n=>({avatarUrl:n.avatarUrl,email:null,graphQLId:n.id,id:n.id.replace(De,""),name:n.name,username:n.username})),commentCount:e.userNotesCount,createdDate:new Date(e.createdAt),description:e.description,graphQLId:e.id,id:e.id.replace(Lt,""),labels:((s=(t=e.labels)==null?void 0:t.nodes)==null?void 0:s.map(Se))??[],number:e.iid,repository:{name:r.name,owner:{login:r.namespace}},updatedDate:new Date(e.updatedAt),upvoteCount:e.upvotes,state:{name:e.state,color:null},type:e.type,title:e.title,url:e.webUrl,milestone:e.milestone?Le(e.milestone,r.webUrl):null}},Le=(e,r)=>({id:e.id.replace(Ke,""),graphQLId:e.id,number:parseInt(e.iid,10),title:e.title,description:e.description,isOpen:e.state==="active",url:`${r}/-/${e.webPath.replace(/.+?\/-\//,"")}`,startDate:e.startDate?new Date(e.startDate):null,dueDate:e.dueDate?new Date(e.dueDate):null}),z=class extends x{async getCurrentUser(r={}){var n;let s=(n=(await f(this.config,{query:`
540
+ ${r?`milestone { ${qe} }`:""}
541
+ `,O=e=>`${e.namespace}/${e.name}`,xt=e=>`${e.namespace}/${e.name}`,De=e=>{var r;return{id:e.id.replace(z,""),graphQLId:e.id,namespace:Ke(e.fullPath),name:e.path,webUrl:e.webUrl,httpsUrl:e.httpUrlToRepo,sshUrl:e.sshUrlToRepo,defaultBranch:(r=e.repository)!=null&&r.rootRef?{name:e.repository.rootRef}:null,permission:null}},Tt={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},N=e=>({id:e.id.replace(Ue,""),graphQLId:e.id,name:e.name,username:e.username,email:e.publicEmail,avatarUrl:e.avatarUrl}),Ge=e=>({color:e.color,description:e.description,id:e.id.replace(Gt,""),graphQLId:e.id,name:e.title}),Ee=(e,r)=>{var t,s,n,a,o,i,u,l,p;return{id:e.id.replace(qt,""),graphQLId:e.id,title:e.title,number:parseInt(e.iid,10),state:Tt[e.state],commentCount:e.userNotesCount||0,upvoteCount:e.upvotes,author:e.author?N(e.author):null,createdDate:new Date(e.createdAt),isDraft:e.draft,repository:{name:r.name,owner:{login:r.namespace}},headRepository:null,headCommit:{buildStatus:null},baseRef:{name:e.targetBranch,oid:((t=e.diffRefs)==null?void 0:t.baseSha)??null},headRef:{name:e.sourceBranch,oid:((s=e.diffRefs)==null?void 0:s.headSha)??null},url:e.webUrl,updatedDate:new Date(e.updatedAt),closedDate:e.mergedAt?new Date(e.mergedAt):null,assignees:(n=e.assignees)!=null&&n.nodes?e.assignees.nodes.map(N):null,reviews:(a=e.reviewers)!=null&&a.nodes?e.reviewers.nodes.map(d=>{var c,g;return{reviewer:N(d),state:(c=d.mergeRequestInteraction)!=null&&c.approved?"APPROVED":((g=d.mergeRequestInteraction)==null?void 0:g.reviewState)==="REVIEWED"?"CHANGES_REQUESTED":"CHANGES_REQUESTED"}}):null,additions:((o=e.diffStatsSummary)==null?void 0:o.additions)||0,deletions:((i=e.diffStatsSummary)==null?void 0:i.deletions)||0,fileCount:((u=e.diffStatsSummary)==null?void 0:u.fileCount)||0,commitCount:e.commitCount||0,mergeableState:Ut[e.mergeStatusEnum],milestone:e.milestone?xe(e.milestone,r.webUrl):null,labels:((p=(l=e.labels)==null?void 0:l.nodes)==null?void 0:p.map(Ge))??[]}},Se=(e,r)=>{var t,s;return{author:{avatarUrl:e.author.avatarUrl,email:null,graphQLId:e.author.id,id:e.author.id.replace(Ue,""),name:e.author.name,username:e.author.username},assignees:e.assignees.nodes.map(n=>({avatarUrl:n.avatarUrl,email:null,graphQLId:n.id,id:n.id.replace(Ue,""),name:n.name,username:n.username})),commentCount:e.userNotesCount,createdDate:new Date(e.createdAt),description:e.description,graphQLId:e.id,id:e.id.replace(Lt,""),labels:((s=(t=e.labels)==null?void 0:t.nodes)==null?void 0:s.map(Ge))??[],number:e.iid,repository:{name:r.name,owner:{login:r.namespace}},updatedDate:new Date(e.updatedAt),upvoteCount:e.upvotes,state:{name:e.state,color:null},type:e.type,title:e.title,url:e.webUrl,milestone:e.milestone?xe(e.milestone,r.webUrl):null}},xe=(e,r)=>({id:e.id.replace(Xe,""),graphQLId:e.id,number:parseInt(e.iid,10),title:e.title,description:e.description,isOpen:e.state==="active",url:`${r}/-/${e.webPath.replace(/.+?\/-\//,"")}`,startDate:e.startDate?new Date(e.startDate):null,dueDate:e.dueDate?new Date(e.dueDate):null}),W=class extends T{async getCurrentUser(r={}){var n;let s=(n=(await f(this.config,{query:`
538
542
  query getCurrentUser {
539
543
  currentUser {
540
- ${T}
544
+ ${A}
541
545
  }
542
546
  }
543
- `},r)).body.data)==null?void 0:n.currentUser;if(!s)throw new Error("Current user not found.");return{data:_(s)}}async getUserForCommit(r,t={}){var o,i,u,l;let s=A(r.repo),a=(l=(u=(i=(o=(await f(this.config,{query:`
547
+ `},r)).body.data)==null?void 0:n.currentUser;if(!s)throw new Error("Current user not found.");return{data:N(s)}}async getUserForCommit(r,t={}){var o,i,u,l;let s=O(r.repo),a=(l=(u=(i=(o=(await f(this.config,{query:`
544
548
  query getUserForCommit($fullPath: ID!, $oid: String!) {
545
549
  project(fullPath: $fullPath) {
546
550
  repository {
@@ -558,32 +562,32 @@ query getUserForCommit($fullPath: ID!, $oid: String!) {
558
562
  query getAccountForEmail($email: String!) {
559
563
  users(search: $email) {
560
564
  nodes {
561
- ${T}
565
+ ${A}
562
566
  }
563
567
  }
564
568
  }
565
- `,variables:{email:r.email}},t)).body.data)==null?void 0:a.users)==null?void 0:o.nodes)==null?void 0:i[0];if(!n)throw new Error("User not found.");return{data:_(n)}}async getAccountForUsername(r,t={}){var a;let n=(a=(await f(this.config,{query:`
569
+ `,variables:{email:r.email}},t)).body.data)==null?void 0:a.users)==null?void 0:o.nodes)==null?void 0:i[0];if(!n)throw new Error("User not found.");return{data:N(n)}}async getAccountForUsername(r,t={}){var a;let n=(a=(await f(this.config,{query:`
566
570
  query getAccountForUsername($username: String!) {
567
571
  user(username: $username) {
568
- ${T}
572
+ ${A}
569
573
  }
570
574
  }
571
- `,variables:{username:r.username}},t)).body.data)==null?void 0:a.user;if(!n)throw new Error("User not found.");return{data:_(n)}}async getRepo(r,t={}){var a;let s=A(r),n=await f(this.config,{query:`
575
+ `,variables:{username:r.username}},t)).body.data)==null?void 0:a.user;if(!n)throw new Error("User not found.");return{data:N(n)}}async getRepo(r,t={}){var a;let s=O(r),n=await f(this.config,{query:`
572
576
  query getRepo($fullPath: ID!) {
573
577
  project(fullPath: $fullPath) {
574
- ${Pe}
578
+ ${Ce}
575
579
  }
576
580
  }
577
- `,variables:{fullPath:s}},t);if(!((a=n.body.data)!=null&&a.project))throw new Error(`Repository ${s} not found`);return{data:ve(n.body.data.project)}}async getRepos(r,t={}){let n=r.map(A).map((u,l)=>`
581
+ `,variables:{fullPath:s}},t);if(!((a=n.body.data)!=null&&a.project))throw new Error(`Repository ${s} not found`);return{data:De(n.body.data.project)}}async getRepos(r,t={}){let n=r.map(O).map((u,l)=>`
578
582
  getRepo_${l}: project(fullPath: "${u}") {
579
- ${Pe}
583
+ ${Ce}
580
584
  }
581
585
  `).join(`
582
586
  `),a=await f(this.config,{query:`
583
587
  query batchGetRepos {
584
588
  ${n}
585
589
  }
586
- `},t);if(!a.body.data)throw new Error(a.statusText||"Unknown error");let o=[],i=[];return r.forEach((u,l)=>{let p=a.body.data[`getRepo_${l}`];p?o.push(ve(p)):i.push({input:u})}),{data:o,errors:i}}async getReposForCurrentUser(r={},t={}){var a,o,i,u,l,p;let s=await f(this.config,{query:`
590
+ `},t);if(!a.body.data)throw new Error(a.statusText||"Unknown error");let o=[],i=[];return r.forEach((u,l)=>{let p=a.body.data[`getRepo_${l}`];p?o.push(De(p)):i.push({input:u})}),{data:o,errors:i}}async getReposForCurrentUser(r={},t={}){var a,o,i,u,l,p;let s=await f(this.config,{query:`
587
591
  query getReposForCurrentUser($after: String) {
588
592
  projects(membership: true first: 100 after: $after) {
589
593
  pageInfo {
@@ -591,11 +595,11 @@ query getReposForCurrentUser($after: String) {
591
595
  hasNextPage
592
596
  }
593
597
  nodes {
594
- ${Pe}
598
+ ${Ce}
595
599
  }
596
600
  }
597
601
  }
598
- `,variables:{after:r.cursor}},t);if(!((a=s.body.data)!=null&&a.projects))throw new Error(((o=s.body.errors)==null?void 0:o[0].message)||s.statusText||"Unknown error");let n=((u=(i=s.body.data)==null?void 0:i.projects)==null?void 0:u.nodes)||[];return{pageInfo:(p=(l=s.body.data)==null?void 0:l.projects)==null?void 0:p.pageInfo,data:n.map(ve)}}async getRefs(r,t,s={}){var u;let n=A(t.repo),a=new URL(`${ye(this.config,s)}/projects/${encodeURIComponent(n)}/repository/${r}`);a.searchParams.set("page",((u=t.page)==null?void 0:u.toString())||"1"),a.searchParams.set("per_page",v.toString());let o=await this.config.request({url:a.toString(),headers:m(s.token||this.config.token)}),i=o.headers["x-next-page"];return{pageInfo:{hasNextPage:!!i,nextPage:i?parseInt(i,10):null},data:o.body.map(l=>({name:l.name,commit:{oid:l.commit.id,authoredDate:new Date(l.commit.authored_date),committedDate:new Date(l.commit.committed_date)}}))}}async getBranches(r,t={}){return this.getRefs("branches",r,t)}async getTags(r,t={}){return this.getRefs("tags",r,t)}async getBlame(r,t={}){let s=A(r.repo),n=new URL(`${ye(this.config,t)}/projects/${encodeURIComponent(s)}/repository/files/${encodeURIComponent(r.path)}/blame`);n.searchParams.set("ref",r.ref);let a=await this.config.request({url:n.toString(),headers:m(t.token||this.config.token)}),o=0;return{data:{ranges:a.body.map(i=>{let u=o+1;return o+=i.lines.length,{startingLine:u,endingLine:o,commit:{oid:i.commit.id,parentOids:i.commit.parent_ids,authoredDate:new Date(i.commit.authored_date),author:{name:i.commit.author_name,email:i.commit.author_email,avatarUrl:null},committedDate:new Date(i.commit.committed_date),committer:{name:i.commit.committer_name,email:i.commit.committer_email,avatarUrl:null},message:i.commit.message,fileCount:null,additions:null,deletions:null}}})}}}async getPullRequestsForUser(r,t={}){var o,i;let s=Ut[r.association],n=await f(this.config,{query:`
602
+ `,variables:{after:r.cursor}},t);if(!((a=s.body.data)!=null&&a.projects))throw new Error(((o=s.body.errors)==null?void 0:o[0].message)||s.statusText||"Unknown error");let n=((u=(i=s.body.data)==null?void 0:i.projects)==null?void 0:u.nodes)||[];return{pageInfo:(p=(l=s.body.data)==null?void 0:l.projects)==null?void 0:p.pageInfo,data:n.map(De)}}async getRefs(r,t,s={}){var u;let n=O(t.repo),a=new URL(`${we(this.config,s)}/projects/${encodeURIComponent(n)}/repository/${r}`);a.searchParams.set("page",((u=t.page)==null?void 0:u.toString())||"1"),a.searchParams.set("per_page",C.toString());let o=await this.config.request({url:a.toString(),headers:m(s.token||this.config.token)}),i=o.headers["x-next-page"];return{pageInfo:{hasNextPage:!!i,nextPage:i?parseInt(i,10):null},data:o.body.map(l=>({name:l.name,commit:{oid:l.commit.id,authoredDate:new Date(l.commit.authored_date),committedDate:new Date(l.commit.committed_date)}}))}}async getBranches(r,t={}){return this.getRefs("branches",r,t)}async getTags(r,t={}){return this.getRefs("tags",r,t)}async getBlame(r,t={}){let s=O(r.repo),n=new URL(`${we(this.config,t)}/projects/${encodeURIComponent(s)}/repository/files/${encodeURIComponent(r.path)}/blame`);n.searchParams.set("ref",r.ref);let a=await this.config.request({url:n.toString(),headers:m(t.token||this.config.token)}),o=0;return{data:{ranges:a.body.map(i=>{let u=o+1;return o+=i.lines.length,{startingLine:u,endingLine:o,commit:{oid:i.commit.id,parentOids:i.commit.parent_ids,authoredDate:new Date(i.commit.authored_date),author:{name:i.commit.author_name,email:i.commit.author_email,avatarUrl:null},committedDate:new Date(i.commit.committed_date),committer:{name:i.commit.committer_name,email:i.commit.committer_email,avatarUrl:null},message:i.commit.message,fileCount:null,additions:null,deletions:null}}})}}}async getPullRequestsForUser(r,t={}){var o,i;let s=St[r.association],n=await f(this.config,{query:`
599
603
  query getPullRequestsForUser($username: String! $cursor: String) {
600
604
  user(username: $username) {
601
605
  ${s}(state:opened first:100 after:$cursor) {
@@ -604,12 +608,12 @@ query getPullRequestsForUser($username: String! $cursor: String) {
604
608
  hasNextPage
605
609
  }
606
610
  nodes {
607
- ${Ce(!0,!0)}
611
+ ${$e(!0,!0)}
608
612
  }
609
613
  }
610
614
  }
611
615
  }
612
- `,variables:{username:r.username,cursor:r.cursor}},t);if(!n.body.data)throw new Error(((o=n.body.errors)==null?void 0:o[0].message)||n.statusText||"Unknown error");if(!n.body.data.user)throw new Error("User not found");let a=n.body.data.user[s];if(!a)throw new Error("Unexpected response");return{pageInfo:a.pageInfo,data:((i=a.nodes)==null?void 0:i.map(u=>Ee(u,k(u.project))))||[]}}async getPullRequestsAssociatedWithUser(r,t={}){var c;let[s,n,a]=((c=r.cursor)==null?void 0:c.split(";"))||[void 0,void 0,void 0];if(r.cursor&&s==="null"&&n==="null"&&a==="null")return{pageInfo:{hasNextPage:!1,endCursor:"null;null;null"},data:[]};let[o,i,u]=await Promise.all([this.getPullRequestsForUser({username:r.username,association:"authored",cursor:s},t),this.getPullRequestsForUser({username:r.username,association:"assigned",cursor:n},t),this.getPullRequestsForUser({username:r.username,association:"reviewRequested",cursor:a},t)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return o.data.forEach(d),i.data.forEach(d),u.data.forEach(d),{pageInfo:{hasNextPage:o.pageInfo.hasNextPage||i.pageInfo.hasNextPage||u.pageInfo.hasNextPage,endCursor:`${(o==null?void 0:o.pageInfo.hasNextPage)&&(o==null?void 0:o.pageInfo.endCursor)||"null"};${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}getVariablesForPullRequests(r){let{updatedBefore:t,isDraft:s,authorLogin:n,assigneeLogins:a,reviewRequestedLogin:o}=r||{},i={},u=[],l=[],p=(d,c,g)=>{u.push(`$${d}: ${g}`),l.push(`${d}: $${d}`),i[d]=c};return t&&p("updatedBefore",t,"Time"),n&&p("authorUsername",n,"String"),a&&p("assigneeUsername",a[0],"String"),s!=null&&p("draft",s,"Boolean"),o&&p("reviewerUsername",o,"String"),{variables:i,variableTypes:u,mergeRequestArguments:l}}async getPullRequestsForRepo(r,t={}){var I,P,y;let{cursor:s,repo:n}=r||{},a=A(n),{variables:o,variableTypes:i,mergeRequestArguments:u}=this.getVariablesForPullRequests(r),l={fullPath:a,...o},p=await f(this.config,{query:`
616
+ `,variables:{username:r.username,cursor:r.cursor}},t);if(!n.body.data)throw new Error(((o=n.body.errors)==null?void 0:o[0].message)||n.statusText||"Unknown error");if(!n.body.data.user)throw new Error("User not found");let a=n.body.data.user[s];if(!a)throw new Error("Unexpected response");return{pageInfo:a.pageInfo,data:((i=a.nodes)==null?void 0:i.map(u=>Ee(u,_(u.project))))||[]}}async getPullRequestsAssociatedWithUser(r,t={}){var c;let[s,n,a]=((c=r.cursor)==null?void 0:c.split(";"))||[void 0,void 0,void 0];if(r.cursor&&s==="null"&&n==="null"&&a==="null")return{pageInfo:{hasNextPage:!1,endCursor:"null;null;null"},data:[]};let[o,i,u]=await Promise.all([this.getPullRequestsForUser({username:r.username,association:"authored",cursor:s},t),this.getPullRequestsForUser({username:r.username,association:"assigned",cursor:n},t),this.getPullRequestsForUser({username:r.username,association:"reviewRequested",cursor:a},t)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return o.data.forEach(d),i.data.forEach(d),u.data.forEach(d),{pageInfo:{hasNextPage:o.pageInfo.hasNextPage||i.pageInfo.hasNextPage||u.pageInfo.hasNextPage,endCursor:`${(o==null?void 0:o.pageInfo.hasNextPage)&&(o==null?void 0:o.pageInfo.endCursor)||"null"};${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}getVariablesForPullRequests(r){let{updatedBefore:t,isDraft:s,authorLogin:n,assigneeLogins:a,reviewRequestedLogin:o}=r||{},i={},u=[],l=[],p=(d,c,g)=>{u.push(`$${d}: ${g}`),l.push(`${d}: $${d}`),i[d]=c};return t&&p("updatedBefore",t,"Time"),n&&p("authorUsername",n,"String"),a&&p("assigneeUsername",a[0],"String"),s!=null&&p("draft",s,"Boolean"),o&&p("reviewerUsername",o,"String"),{variables:i,variableTypes:u,mergeRequestArguments:l}}async getPullRequestsForRepo(r,t={}){var I,P,y;let{cursor:s,repo:n}=r||{},a=O(n),{variables:o,variableTypes:i,mergeRequestArguments:u}=this.getVariablesForPullRequests(r),l={fullPath:a,...o},p=await f(this.config,{query:`
613
617
  query getPullRequestsForRepo(
614
618
  $fullPath: ID!
615
619
  $after: String
@@ -633,12 +637,12 @@ query getPullRequestsForRepo(
633
637
  hasNextPage
634
638
  }
635
639
  nodes {
636
- ${Ce(!1,!0)}
640
+ ${$e(!1,!0)}
637
641
  }
638
642
  }
639
643
  }
640
644
  }
641
- `,variables:{...l,after:s}},t),d=[],c=(I=p.body.data)==null?void 0:I.project,g=k(c||{fullPath:"",path:"",webUrl:""});return(((P=c==null?void 0:c.mergeRequests)==null?void 0:P.nodes)||[]).forEach(b=>{d.push(Ee(b,g))}),{pageInfo:(y=c==null?void 0:c.mergeRequests)==null?void 0:y.pageInfo,data:d}}async getPullRequestsForRepos(r,t={}){var c,g,R,I,P;let{cursor:s}=r||{},n=r.repoIds.map(y=>y.toString().startsWith(M)?y:`${M}${y}`),{variables:a,variableTypes:o,mergeRequestArguments:i}=this.getVariablesForPullRequests(r),u={projectIds:n,...a},l=await f(this.config,{query:`
645
+ `,variables:{...l,after:s}},t),d=[],c=(I=p.body.data)==null?void 0:I.project,g=_(c||{fullPath:"",path:"",webUrl:""});return(((P=c==null?void 0:c.mergeRequests)==null?void 0:P.nodes)||[]).forEach(b=>{d.push(Ee(b,g))}),{pageInfo:(y=c==null?void 0:c.mergeRequests)==null?void 0:y.pageInfo,data:d}}async getPullRequestsForRepos(r,t={}){var c,g,R,I,P;let{cursor:s}=r||{},n=r.repoIds.map(y=>y.toString().startsWith(z)?y:`${z}${y}`),{variables:a,variableTypes:o,mergeRequestArguments:i}=this.getVariablesForPullRequests(r),u={projectIds:n,...a},l=await f(this.config,{query:`
642
646
  query getPullRequests(
643
647
  $projectIds: [ID!]
644
648
  $after: String
@@ -663,13 +667,13 @@ query getPullRequests(
663
667
  ${i.length?i.join(" "):""}
664
668
  ) {
665
669
  nodes {
666
- ${Ce(!1,!1)}
670
+ ${$e(!1,!1)}
667
671
  }
668
672
  }
669
673
  }
670
674
  }
671
675
  }
672
- `,variables:{...u,after:s}},t),p=[];return(((g=(c=l.body.data)==null?void 0:c.projects)==null?void 0:g.nodes)||[]).forEach(y=>{var L;let b=k(y);(((L=y.mergeRequests)==null?void 0:L.nodes)||[]).forEach(V=>{p.push(Ee(V,b))})}),{pageInfo:(P=(I=(R=l.body)==null?void 0:R.data)==null?void 0:I.projects)==null?void 0:P.pageInfo,data:p}}async closePullRequest(r,t={}){var l,p,d;let{repo:{namespace:s,name:n},pullRequestId:a}=r,o=`mutation ClosePullRequest($fullPath: ID!, $pullRequestId: String!) {
676
+ `,variables:{...u,after:s}},t),p=[];return(((g=(c=l.body.data)==null?void 0:c.projects)==null?void 0:g.nodes)||[]).forEach(y=>{var L;let b=_(y);(((L=y.mergeRequests)==null?void 0:L.nodes)||[]).forEach(D=>{p.push(Ee(D,b))})}),{pageInfo:(P=(I=(R=l.body)==null?void 0:R.data)==null?void 0:I.projects)==null?void 0:P.pageInfo,data:p}}async closePullRequest(r,t={}){var l,p,d;let{repo:{namespace:s,name:n},pullRequestId:a}=r,o=`mutation ClosePullRequest($fullPath: ID!, $pullRequestId: String!) {
673
677
  mergeRequestUpdate(input: { projectPath: $fullPath, iid: $pullRequestId, state: CLOSED }) {
674
678
  errors,
675
679
  mergeRequest {
@@ -704,11 +708,11 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
704
708
  fullPath
705
709
  webUrl
706
710
  issue(iid: $issueId) {
707
- ${we}
711
+ ${ve}
708
712
  }
709
713
  }
710
714
  }
711
- `,variables:{issueId:r.id,projectId:s}},t);if(!((a=n.body.data)!=null&&a.project))throw new Error(`Repository ${s} not found`);if(!((i=(o=n.body.data)==null?void 0:o.project)!=null&&i.issue))throw new Error(`Issue ${r.id} not found`);return{data:$e(n.body.data.project.issue,k(n.body.data.project))}}getVariablesForIssues(r){let{updatedBefore:t,authorLogin:s,assigneeLogins:n}=r||{},a={},o=[],i=[],u=(l,p,d)=>{o.push(`$${l}: ${d}`),i.push(`${l}: $${l}`),a[l]=p};return t&&u("updatedBefore",t,"Time"),s&&u("authorUsername",s,"String"),n&&u("assigneeUsername",n[0],"String"),{variables:a,variableTypes:o,issueArguments:i}}async getIssuesForRepo(r,t={}){var P,y,b;let{cursor:s,repo:n}=r||{},a=A(n),{variables:o,variableTypes:i,issueArguments:u}=this.getVariablesForIssues(r),l={fullPath:a,...o},p=`
715
+ `,variables:{issueId:r.id,projectId:s}},t);if(!((a=n.body.data)!=null&&a.project))throw new Error(`Repository ${s} not found`);if(!((i=(o=n.body.data)==null?void 0:o.project)!=null&&i.issue))throw new Error(`Issue ${r.id} not found`);return{data:Se(n.body.data.project.issue,_(n.body.data.project))}}getVariablesForIssues(r){let{updatedBefore:t,authorLogin:s,assigneeLogins:n}=r||{},a={},o=[],i=[],u=(l,p,d)=>{o.push(`$${l}: ${d}`),i.push(`${l}: $${l}`),a[l]=p};return t&&u("updatedBefore",t,"Time"),s&&u("authorUsername",s,"String"),n&&u("assigneeUsername",n[0],"String"),{variables:a,variableTypes:o,issueArguments:i}}async getIssuesForRepo(r,t={}){var P,y,b;let{cursor:s,repo:n}=r||{},a=O(n),{variables:o,variableTypes:i,issueArguments:u}=this.getVariablesForIssues(r),l={fullPath:a,...o},p=`
712
716
  query GetIssuesFromProject(
713
717
  $fullPath: ID!
714
718
  $after: String
@@ -728,7 +732,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
728
732
  ${u.length?u.join(" "):""}
729
733
  ) {
730
734
  nodes {
731
- ${we}
735
+ ${ve}
732
736
  }
733
737
  pageInfo {
734
738
  endCursor
@@ -736,7 +740,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
736
740
  }
737
741
  }
738
742
  }
739
- }`,d=await f(this.config,{query:p,variables:{...l,after:s}},t),c=[],g=(P=d.body.data)==null?void 0:P.project,R=k(g||{fullPath:"",path:"",webUrl:""});return(((y=g==null?void 0:g.issues)==null?void 0:y.nodes)||[]).forEach(w=>{c.push($e(w,R))}),{pageInfo:(b=g==null?void 0:g.issues)==null?void 0:b.pageInfo,data:c.sort((w,L)=>(w.updatedDate||w.createdDate).getTime()-(L.updatedDate||L.createdDate).getTime())}}async getIssuesForRepos(r,t={}){var g,R,I,P,y;let{cursor:s}=r||{},n=r.repoIds.map(b=>b.toString().startsWith(M)?b:`${M}${b}`),{variables:a,variableTypes:o,mergeRequestArguments:i}=this.getVariablesForPullRequests(r),u={projectIds:n,...a},l=`
743
+ }`,d=await f(this.config,{query:p,variables:{...l,after:s}},t),c=[],g=(P=d.body.data)==null?void 0:P.project,R=_(g||{fullPath:"",path:"",webUrl:""});return(((y=g==null?void 0:g.issues)==null?void 0:y.nodes)||[]).forEach(v=>{c.push(Se(v,R))}),{pageInfo:(b=g==null?void 0:g.issues)==null?void 0:b.pageInfo,data:c.sort((v,L)=>(v.updatedDate||v.createdDate).getTime()-(L.updatedDate||L.createdDate).getTime())}}async getIssuesForRepos(r,t={}){var g,R,I,P,y;let{cursor:s}=r||{},n=r.repoIds.map(b=>b.toString().startsWith(z)?b:`${z}${b}`),{variables:a,variableTypes:o,mergeRequestArguments:i}=this.getVariablesForPullRequests(r),u={projectIds:n,...a},l=`
740
744
  query GetIssuesFromProject(
741
745
  $projectIds: [ID!]
742
746
  $after: String
@@ -761,18 +765,18 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
761
765
  ${i.length?i.join(" "):""}
762
766
  ) {
763
767
  nodes {
764
- ${we}
768
+ ${ve}
765
769
  }
766
770
  }
767
771
  }
768
772
  }
769
- }`,p=await f(this.config,{query:l,variables:{...u,after:s}},t),d=[];return(((R=(g=p.body.data)==null?void 0:g.projects)==null?void 0:R.nodes)||[]).forEach(b=>{var V;let w=k(b);(((V=b.issues)==null?void 0:V.nodes)||[]).forEach(Xe=>d.push($e(Xe,w)))}),{pageInfo:(y=(P=(I=p.body)==null?void 0:I.data)==null?void 0:P.projects)==null?void 0:y.pageInfo,data:d.sort((b,w)=>(b.updatedDate||b.createdDate).getTime()-(w.updatedDate||w.createdDate).getTime())}}async setIssueStatus(r,t={}){var l,p,d;let{repo:{namespace:s,name:n},issueId:a,status:o}=r,i=`mutation SetIssueState($fullPath: ID!, $issueId: String!, $status: IssueStateEvent!) {
773
+ }`,p=await f(this.config,{query:l,variables:{...u,after:s}},t),d=[];return(((R=(g=p.body.data)==null?void 0:g.projects)==null?void 0:R.nodes)||[]).forEach(b=>{var D;let v=_(b);(((D=b.issues)==null?void 0:D.nodes)||[]).forEach(ue=>d.push(Se(ue,v)))}),{pageInfo:(y=(P=(I=p.body)==null?void 0:I.data)==null?void 0:P.projects)==null?void 0:y.pageInfo,data:d.sort((b,v)=>(b.updatedDate||b.createdDate).getTime()-(v.updatedDate||v.createdDate).getTime())}}async setIssueStatus(r,t={}){var l,p,d;let{repo:{namespace:s,name:n},issueId:a,status:o}=r,i=`mutation SetIssueState($fullPath: ID!, $issueId: String!, $status: IssueStateEvent!) {
770
774
  updateIssue(input: { projectPath: $fullPath, iid: $issueId, stateEvent: $status }) {
771
775
  issue {
772
776
  id
773
777
  }
774
778
  }
775
- }`;if(!((d=(p=(l=(await f(this.config,{query:i,variables:{fullPath:`${s}/${n}`,issueId:a,status:o}},t)).body.data)==null?void 0:l.updateIssue)==null?void 0:p.issue)!=null&&d.id))throw new Error("Could not set issue status")}async setIssueMilestone(r,t={}){var p,d,c,g;let{repo:{namespace:s,name:n},issueId:a}=r,o=((p=r.milestoneGraphQLId)==null?void 0:p.replace(Ke,""))??"",i=`mutation SetIssueMilestone($fullPath: ID!, $issueId: String!, $milestoneGraphQLId: ID) {
779
+ }`;if(!((d=(p=(l=(await f(this.config,{query:i,variables:{fullPath:`${s}/${n}`,issueId:a,status:o}},t)).body.data)==null?void 0:l.updateIssue)==null?void 0:p.issue)!=null&&d.id))throw new Error("Could not set issue status")}async setIssueMilestone(r,t={}){var p,d,c,g;let{repo:{namespace:s,name:n},issueId:a}=r,o=((p=r.milestoneGraphQLId)==null?void 0:p.replace(Xe,""))??"",i=`mutation SetIssueMilestone($fullPath: ID!, $issueId: String!, $milestoneGraphQLId: ID) {
776
780
  updateIssue(input: { projectPath: $fullPath, iid: $issueId, milestoneId: $milestoneGraphQLId }) {
777
781
  errors
778
782
  issue {
@@ -793,7 +797,7 @@ query getLabelsForRepo(
793
797
  webUrl
794
798
  milestones(after: $after) {
795
799
  nodes {
796
- ${Ue}
800
+ ${qe}
797
801
  }
798
802
  pageInfo {
799
803
  endCursor
@@ -802,7 +806,7 @@ query getLabelsForRepo(
802
806
  }
803
807
  }
804
808
  }
805
- `,variables:{fullPath:`${s}/${n}`,after:a}},t);return{pageInfo:((l=(u=(i=o.body.data)==null?void 0:i.project)==null?void 0:u.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=o.body.data)==null?void 0:p.project)==null?void 0:d.milestones)==null?void 0:c.nodes)==null?void 0:g.map(R=>{var I,P;return Le(R,((P=(I=o.body.data)==null?void 0:I.project)==null?void 0:P.webUrl)||"")}))??[]}}async getLabelsForRepo(r,t={}){var i,u,l,p,d,c,g;let{repo:{namespace:s,name:n},cursor:a}=r,o=await f(this.config,{query:`
809
+ `,variables:{fullPath:`${s}/${n}`,after:a}},t);return{pageInfo:((l=(u=(i=o.body.data)==null?void 0:i.project)==null?void 0:u.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=o.body.data)==null?void 0:p.project)==null?void 0:d.milestones)==null?void 0:c.nodes)==null?void 0:g.map(R=>{var I,P;return xe(R,((P=(I=o.body.data)==null?void 0:I.project)==null?void 0:P.webUrl)||"")}))??[]}}async getLabelsForRepo(r,t={}){var i,u,l,p,d,c,g;let{repo:{namespace:s,name:n},cursor:a}=r,o=await f(this.config,{query:`
806
810
  query getLabelsForRepo(
807
811
  $fullPath: ID!
808
812
  $after: String
@@ -812,7 +816,7 @@ query getLabelsForRepo(
812
816
  ) {
813
817
  labels(after: $after) {
814
818
  nodes {
815
- ${qe}
819
+ ${Le}
816
820
  }
817
821
  pageInfo {
818
822
  endCursor
@@ -821,4 +825,4 @@ query getLabelsForRepo(
821
825
  }
822
826
  }
823
827
  }
824
- `,variables:{fullPath:`${s}/${n}`,after:a}},t);return{pageInfo:((l=(u=(i=o.body.data)==null?void 0:i.project)==null?void 0:u.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=o.body.data)==null?void 0:p.project)==null?void 0:d.labels)==null?void 0:c.nodes)==null?void 0:g.map(Se))??[]}}};var W="https://api.atlassian.com/ex/jira",Ge=100,At=e=>{var t,s,n,a,o,i;let r=e.fields.assignee;return{id:e.id,commentCount:e.fields.comment.comments.length,number:e.key,title:e.fields.summary,url:e.self,createdDate:new Date(e.fields.created),author:{id:e.fields.creator.accountId,name:e.fields.creator.displayName,email:e.fields.creator.emailAddress,avatarUrl:e.fields.creator.avatarUrls["32x32"],username:e.fields.creator.displayName},updatedDate:new Date(e.fields.updated),assignees:r?[{id:r.accountId,name:r.displayName,email:r.emailAddress,avatarUrl:r.avatarUrls["32x32"],username:r.displayName}]:[],description:null,repository:null,state:{name:(t=e.fields.status)==null?void 0:t.name,color:(n=(s=e.fields.status)==null?void 0:s.statusCategory)==null?void 0:n.colorName},statusTransitions:((a=e.transitions)==null?void 0:a.map(Ot))??[],type:e.fields.issuetype.name,upvoteCount:((o=e.fields.votes)==null?void 0:o.votes)||0,labels:((i=e.fields.labels)==null?void 0:i.map(u=>({color:null,description:null,id:null,name:u})))??[]}},Ot=e=>({name:e.name,id:e.id}),H=class extends ${async getCurrentUserForResource(r,t={}){let s=await this.config.request({url:`${t.baseUrl||W}/${r.resourceId}/rest/api/2/myself`,headers:m(t.token||this.config.token)});return{data:{name:s.body.displayName,email:s.body.emailAddress,avatarUrl:s.body.avatarUrls["48x48"],id:s.body.accountId,username:s.body.displayName}}}async getJiraResourcesForCurrentUser(r={}){return{data:(await this.config.request({url:`${r.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:m(r.token||this.config.token)})).body.map(s=>({avatarUrl:s.avatarUrl,id:s.id,name:s.name}))}}async getJiraProjectsForResource(r,t={}){let s=new URL(`${t.baseUrl||W}/${r.resourceId}/rest/api/2/project/search`);s.searchParams.set("maxResults",Ge.toString()),r.cursor&&s.searchParams.set("startAt",r.cursor);let n=await this.config.request({url:s.toString(),headers:m(t.token||this.config.token)});return{pageInfo:{hasNextPage:n.body.values.length!==0,endCursor:(n.body.startAt+n.body.values.length).toString()},data:n.body.values.map(a=>({id:a.id,name:a.name,resourceId:r.resourceId}))}}async getJiraProjectsForResources(r,t={}){let s=[];return await Promise.all(r.resourceIds.map(async n=>{let a=await this.getJiraProjectsForResource({resourceId:n},t);s.push(...a.data)})),{data:s}}async getIssuesForProject(r,t={}){let{assigneeLogins:s,authorLogin:n,mentionLogin:a,project:o}=r||{},i=[`project = "${o}"`];return n&&i.push(`creator in (${n})`),s&&i.push(`assignee in (${s.join(", ")})`),a&&i.push(`comment ~ ${a}`),{data:(await this.config.request({url:`${t.baseUrl||W}/${r.resourceId}/rest/api/2/search?jql=${i.join(" AND ")}&startAt=0&maxResults=${Ge}&fields=${["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels"].join(",")}&expand=transitions`,headers:m(t.token||this.config.token)})).body.issues.map(At)}}async setIssueStatus(r,t={}){let{resourceId:s,issueId:n,status:a}=r,o={transition:{id:a}};try{await this.config.request({method:"POST",url:`${t.baseUrl||W}/${s}/rest/api/2/issue/${n}/transitions`,body:JSON.stringify(o),headers:{...m(t.token||this.config.token),"Content-Type":"application/json"}})}catch(i){if(i.message=="Unexpected end of JSON input")return;throw new Error("Could not set issue status")}}async getLabelsForResource(r,t={}){let{resourceId:s,cursor:n}=r,a=new URL(`${t.baseUrl||W}/${s}/rest/api/2/label`);a.searchParams.set("maxResults",Ge.toString()),n&&a.searchParams.set("startAt",n);let o=await this.config.request({url:a.toString(),headers:m(t.token||this.config.token)});return{pageInfo:{hasNextPage:!o.body.isLast,endCursor:(o.body.startAt+o.body.values.length).toString()},data:o.body.values.map(i=>({color:null,description:null,id:null,name:i}))}}};var N="https://api.trello.com",kt=1e3,_t=(e,r)=>{let t=new Date(1e3*parseInt(e.id.substring(0,8),16));return{id:e.id,commentCount:e.badges.comments,number:e.idShort.toString(),title:e.name,url:e.url,createdDate:new Date(t.toISOString()),author:null,updatedDate:new Date(e.dateLastActivity),assignees:e.idMembers.map(s=>({id:s,username:null,name:null,email:null,avatarUrl:null})),description:null,state:r[e.idList??""]?{name:r[e.idList].name,color:null}:null,type:null,repository:null,upvoteCount:e.badges.votes,labels:e.labels.map(s=>({color:s.color,description:null,id:s.id,name:s.name}))}},J=class extends ${async getCurrentUser(r,t={}){let s=await this.config.request({url:`${t.baseUrl||N}/1/members/me?key=${r.appKey}&token=${t.token||this.config.token}`,headers:m(t.token||this.config.token)});return{data:{name:s.body.fullName,email:s.body.email,avatarUrl:s.body.avatarHash?`https://trello-members.s3.amazonaws.com/${s.body.id}/${s.body.avatarHash}/50.png`:null,id:s.body.id,username:s.body.username}}}async getBoardsForCurrentUser(r,t={}){return{data:(await this.config.request({url:`${t.baseUrl||N}/1/members/me/boards?fields=name&key=${r.appKey}&token=${t.token||this.config.token}&filter=open`,headers:m(t.token||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getListsForTrelloBoard(r,t={}){let{appKey:s,boardId:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||N}/1/boards/${n}/lists?key=${s}&token=${t.token||this.config.token}`,headers:m(t.token||this.config.token)})).body}}async getIssuesForBoard(r,t={}){let s=["-is:archived","sort:edited"],{appKey:n,boardId:a,filterText:o,assigneeLogins:i,trelloBoardListsById:u}=r||{};i&&s.push("@me");let l=`${o?`${o}`:""}${s.join(" ")} board:${a}`;return{data:(await this.config.request({url:`${t.baseUrl||N}/1/search?key=${n}&query=${l}&cards_limit=${kt}&token=${t.token||this.config.token}`,headers:m(t.token||this.config.token)})).body.cards.map(d=>_t(d,u||{}))}}async setIssueStatus(r,t={}){let{appKey:s,cardId:n,status:a}=r;if(!(await this.config.request({method:"PUT",url:`${t.baseUrl||N}/1/cards/${n}?key=${s}&token=${t.token||this.config.token}&idList=${a}`,headers:m(t.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async getLabelsForBoard(r,t={}){let{appKey:s,boardId:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||N}/1/boards/${n}/labels?key=${s}&token=${t.token||this.config.token}`,headers:m(t.token||this.config.token)})).body.map(o=>({color:o.color,description:null,id:o.id,name:o.name}))}}};var te={};G(te,{getIssueUniqueId:()=>Nt,getPullRequestUniqueId:()=>Qt});var Nt=(e,r,t,s="")=>{let n=[];return n.push(s),n.push(e),n.push(r),n.push(t),JSON.stringify(n)},Qt=(e,r,t,s,n="")=>{let a=[];return a.push(n),a.push(e),a.push(r),a.push(t),a.push(s),JSON.stringify(a)};var re={};G(re,{getIssueUniqueId:()=>Bt,getPullRequestUniqueId:()=>jt});var Bt=(e,r)=>JSON.stringify(["",e,r]),jt=(e,r)=>JSON.stringify(["",e,r]);var se={};G(se,{getIssueUniqueId:()=>Ft,getPullRequestUniqueId:()=>Mt});var Ft=(e,r,t)=>JSON.stringify([t,e,r]),Mt=(e,r,t)=>JSON.stringify([t,e,r]);var ne={};G(ne,{getIssueUniqueId:()=>zt,getPullRequestRank:()=>Ht,getPullRequestUniqueId:()=>Wt});var zt=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)},Wt=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)},Ht=(e,r,t)=>{var o,i,u;let s=0,n,a;return(o=e.reviews)==null||o.forEach(l=>{l.reviewer.id===r&&(n=l.state),l.state==="CHANGES_REQUESTED"?a="CHANGES_REQUESTED":l.state==="APPROVED"&&a!=="CHANGES_REQUESTED"&&(a="APPROVED")}),a||(a="REVIEW_REQUESTED"),((i=e.author)==null?void 0:i.id)===r?s+=1e3:(u=e.assignees)!=null&&u.find(l=>l.id===r)?s+=900:n==="REVIEW_REQUESTED"?s+=800:t&&(s+=700),a==="APPROVED"?e.mergeableState==="MERGEABLE"?s+=100:e.mergeableState==="CONFLICTS"?s+=90:s+=80:a=="CHANGES_REQUESTED"&&(s+=70),s};var oe={};G(oe,{getIssueUniqueId:()=>Jt,getPullRequestUniqueId:()=>Vt});var Jt=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)},Vt=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)};var ae={};G(ae,{getIssueUniqueId:()=>Kt,getJiraServerIssueUniqueId:()=>Xt});var Kt=(e,r,t)=>{let s=[];return s.push(""),s.push(e),s.push(r),s.push(t),JSON.stringify(s)},Xt=(e,r,t)=>{let s=[];return s.push(t),s.push(""),s.push(e),s.push(r),JSON.stringify(s)};var ie={};G(ie,{getIssueUniqueId:()=>Zt});var Zt=(e,r,t,s="")=>{let n=[];return n.push(s),n.push(e),n.push(r),n.push(t),JSON.stringify(n)};var Yt=e=>{let r={request:e==null?void 0:e.request};return{azureDevOps:new Q({...r,...e==null?void 0:e.azureDevOps}),bitbucket:new B({...r,...e==null?void 0:e.bitbucket}),bitbucketServer:new j({...r,...e==null?void 0:e.bitbucketServer}),github:new F({...r,...e==null?void 0:e.github}),gitlab:new z({...r,...e==null?void 0:e.gitlab}),jira:new H({...r,...e==null?void 0:e.jira}),trello:new J({...r,...e==null?void 0:e.trello})}},er=Yt;var tr={azureDevOps:te,bitbucket:re,bitbucketServer:se,github:ne,gitlab:oe,jira:ae,trello:ie};
828
+ `,variables:{fullPath:`${s}/${n}`,after:a}},t);return{pageInfo:((l=(u=(i=o.body.data)==null?void 0:i.project)==null?void 0:u.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=o.body.data)==null?void 0:p.project)==null?void 0:d.labels)==null?void 0:c.nodes)==null?void 0:g.map(Ge))??[]}}};var H="https://api.atlassian.com/ex/jira",Te=100,At=e=>{var t,s,n,a,o,i;let r=e.fields.assignee;return{id:e.id,commentCount:e.fields.comment.comments.length,number:e.key,title:e.fields.summary,url:e.self,createdDate:new Date(e.fields.created),author:{id:e.fields.creator.accountId,name:e.fields.creator.displayName,email:e.fields.creator.emailAddress,avatarUrl:e.fields.creator.avatarUrls["32x32"],username:e.fields.creator.displayName},updatedDate:new Date(e.fields.updated),assignees:r?[{id:r.accountId,name:r.displayName,email:r.emailAddress,avatarUrl:r.avatarUrls["32x32"],username:r.displayName}]:[],description:null,repository:null,state:{name:(t=e.fields.status)==null?void 0:t.name,color:(n=(s=e.fields.status)==null?void 0:s.statusCategory)==null?void 0:n.colorName},statusTransitions:((a=e.transitions)==null?void 0:a.map(Ot))??[],type:e.fields.issuetype.name,upvoteCount:((o=e.fields.votes)==null?void 0:o.votes)||0,labels:((i=e.fields.labels)==null?void 0:i.map(u=>({color:null,description:null,id:null,name:u})))??[]}},Ot=e=>({name:e.name,id:e.id}),J=class extends E{async getCurrentUserForResource(r,t={}){let s=await this.config.request({url:`${t.baseUrl||H}/${r.resourceId}/rest/api/2/myself`,headers:m(t.token||this.config.token)});return{data:{name:s.body.displayName,email:s.body.emailAddress,avatarUrl:s.body.avatarUrls["48x48"],id:s.body.accountId,username:s.body.displayName}}}async getJiraResourcesForCurrentUser(r={}){return{data:(await this.config.request({url:`${r.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:m(r.token||this.config.token)})).body.map(s=>({avatarUrl:s.avatarUrl,id:s.id,name:s.name}))}}async getJiraProjectsForResource(r,t={}){let s=new URL(`${t.baseUrl||H}/${r.resourceId}/rest/api/2/project/search`);s.searchParams.set("maxResults",Te.toString()),r.cursor&&s.searchParams.set("startAt",r.cursor);let n=await this.config.request({url:s.toString(),headers:m(t.token||this.config.token)});return{pageInfo:{hasNextPage:n.body.values.length!==0,endCursor:(n.body.startAt+n.body.values.length).toString()},data:n.body.values.map(a=>({id:a.id,name:a.name,resourceId:r.resourceId}))}}async getJiraProjectsForResources(r,t={}){let s=[];return await Promise.all(r.resourceIds.map(async n=>{let a=await this.getJiraProjectsForResource({resourceId:n},t);s.push(...a.data)})),{data:s}}async getIssuesForProject(r,t={}){let{assigneeLogins:s,authorLogin:n,mentionLogin:a,project:o}=r||{},i=[`project = "${o}"`];return n&&i.push(`creator in ("${n}")`),s&&s.length!==0&&i.push(`assignee in ("${s.join('", "')}")`),a&&i.push(`comment ~ "${a}"`),{data:(await this.config.request({url:`${t.baseUrl||H}/${r.resourceId}/rest/api/2/search?jql=${i.join(" AND ")}&startAt=0&maxResults=${Te}&fields=${["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels"].join(",")}&expand=transitions`,headers:m(t.token||this.config.token)})).body.issues.map(At)}}async setIssueStatus(r,t={}){let{resourceId:s,issueId:n,status:a}=r,o={transition:{id:a}};await this.config.request({method:"POST",url:`${t.baseUrl||H}/${s}/rest/api/2/issue/${n}/transitions`,body:JSON.stringify(o),headers:{...m(t.token||this.config.token),"Content-Type":"application/json"}})}async getLabelsForResource(r,t={}){let{resourceId:s,cursor:n}=r,a=new URL(`${t.baseUrl||H}/${s}/rest/api/2/label`);a.searchParams.set("maxResults",Te.toString()),n&&a.searchParams.set("startAt",n);let o=await this.config.request({url:a.toString(),headers:m(t.token||this.config.token)});return{pageInfo:{hasNextPage:!o.body.isLast,endCursor:(o.body.startAt+o.body.values.length).toString()},data:o.body.values.map(i=>({color:null,description:null,id:null,name:i}))}}};var Q="https://api.trello.com",kt=1e3,_t=(e,r)=>{let t=new Date(1e3*parseInt(e.id.substring(0,8),16));return{id:e.id,commentCount:e.badges.comments,number:e.idShort.toString(),title:e.name,url:e.url,createdDate:new Date(t.toISOString()),author:null,updatedDate:new Date(e.dateLastActivity),assignees:e.idMembers.map(s=>({id:s,username:null,name:null,email:null,avatarUrl:null})),description:null,state:r[e.idList??""]?{name:r[e.idList].name,color:null}:null,type:null,repository:null,upvoteCount:e.badges.votes,labels:e.labels.map(s=>({color:s.color,description:null,id:s.id,name:s.name}))}},V=class extends E{async getCurrentUser(r,t={}){let s=await this.config.request({url:`${t.baseUrl||Q}/1/members/me?key=${r.appKey}&token=${t.token||this.config.token}`,headers:m(t.token||this.config.token)});return{data:{name:s.body.fullName,email:s.body.email,avatarUrl:s.body.avatarHash?`https://trello-members.s3.amazonaws.com/${s.body.id}/${s.body.avatarHash}/50.png`:null,id:s.body.id,username:s.body.username}}}async getBoardsForCurrentUser(r,t={}){return{data:(await this.config.request({url:`${t.baseUrl||Q}/1/members/me/boards?fields=name&key=${r.appKey}&token=${t.token||this.config.token}&filter=open`,headers:m(t.token||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getListsForTrelloBoard(r,t={}){let{appKey:s,boardId:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||Q}/1/boards/${n}/lists?key=${s}&token=${t.token||this.config.token}`,headers:m(t.token||this.config.token)})).body}}async getIssuesForBoard(r,t={}){let s=["-is:archived","sort:edited"],{appKey:n,boardId:a,filterText:o,assigneeLogins:i,trelloBoardListsById:u}=r||{};i&&s.push("@me");let l=`${o?`${o}`:""}${s.join(" ")} board:${a}`;return{data:(await this.config.request({url:`${t.baseUrl||Q}/1/search?key=${n}&query=${l}&cards_limit=${kt}&token=${t.token||this.config.token}`,headers:m(t.token||this.config.token)})).body.cards.map(d=>_t(d,u||{}))}}async setIssueStatus(r,t={}){let{appKey:s,cardId:n,status:a}=r;if(!(await this.config.request({method:"PUT",url:`${t.baseUrl||Q}/1/cards/${n}?key=${s}&token=${t.token||this.config.token}&idList=${a}`,headers:m(t.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async getLabelsForBoard(r,t={}){let{appKey:s,boardId:n}=r;return{data:(await this.config.request({url:`${t.baseUrl||Q}/1/boards/${n}/labels?key=${s}&token=${t.token||this.config.token}`,headers:m(t.token||this.config.token)})).body.map(o=>({color:o.color,description:null,id:o.id,name:o.name}))}}};var te={};x(te,{getIssueUniqueId:()=>Nt,getPullRequestUniqueId:()=>Qt});var Nt=(e,r,t,s="")=>{let n=[];return n.push(s),n.push(e),n.push(r),n.push(t),JSON.stringify(n)},Qt=(e,r,t,s,n="")=>{let a=[];return a.push(n),a.push(e),a.push(r),a.push(t),a.push(s),JSON.stringify(a)};var re={};x(re,{getIssueUniqueId:()=>Bt,getPullRequestUniqueId:()=>jt});var Bt=(e,r)=>JSON.stringify(["",e,r]),jt=(e,r)=>JSON.stringify(["",e,r]);var se={};x(se,{getIssueUniqueId:()=>Ft,getPullRequestUniqueId:()=>Mt});var Ft=(e,r,t)=>JSON.stringify([t,e,r]),Mt=(e,r,t)=>JSON.stringify([t,e,r]);var ne={};x(ne,{getIssueUniqueId:()=>zt,getPullRequestRank:()=>Ht,getPullRequestUniqueId:()=>Wt});var zt=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)},Wt=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)},Ht=(e,r,t)=>{var o,i,u;let s=0,n,a;return(o=e.reviews)==null||o.forEach(l=>{l.reviewer.id===r&&(n=l.state),l.state==="CHANGES_REQUESTED"?a="CHANGES_REQUESTED":l.state==="APPROVED"&&a!=="CHANGES_REQUESTED"&&(a="APPROVED")}),a||(a="REVIEW_REQUESTED"),((i=e.author)==null?void 0:i.id)===r?s+=1e3:(u=e.assignees)!=null&&u.find(l=>l.id===r)?s+=900:n==="REVIEW_REQUESTED"?s+=800:t&&(s+=700),a==="APPROVED"?e.mergeableState==="MERGEABLE"?s+=100:e.mergeableState==="CONFLICTS"?s+=90:s+=80:a=="CHANGES_REQUESTED"&&(s+=70),s};var oe={};x(oe,{getIssueUniqueId:()=>Jt,getPullRequestUniqueId:()=>Vt});var Jt=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)},Vt=(e,r="")=>{let t=[];return t.push(r),t.push(e),JSON.stringify(t)};var ae={};x(ae,{getIssueUniqueId:()=>Kt,getJiraServerIssueUniqueId:()=>Xt});var Kt=(e,r,t)=>{let s=[];return s.push(""),s.push(e),s.push(r),s.push(t),JSON.stringify(s)},Xt=(e,r,t)=>{let s=[];return s.push(t),s.push(""),s.push(e),s.push(r),JSON.stringify(s)};var ie={};x(ie,{getIssueUniqueId:()=>Zt});var Zt=(e,r,t,s="")=>{let n=[];return n.push(s),n.push(e),n.push(r),n.push(t),JSON.stringify(n)};var Yt=e=>{let r={request:e==null?void 0:e.request};return{azureDevOps:new B({...r,...e==null?void 0:e.azureDevOps}),bitbucket:new j({...r,...e==null?void 0:e.bitbucket}),bitbucketServer:new F({...r,...e==null?void 0:e.bitbucketServer}),github:new M({...r,...e==null?void 0:e.github}),gitlab:new W({...r,...e==null?void 0:e.gitlab}),jira:new J({...r,...e==null?void 0:e.jira}),trello:new V({...r,...e==null?void 0:e.trello})}},er=Yt;var tr={azureDevOps:te,bitbucket:re,bitbucketServer:se,github:ne,gitlab:oe,jira:ae,trello:ie};
@@ -74,6 +74,15 @@ export declare class Bitbucket extends Provider implements GitProvider {
74
74
  };
75
75
  }[];
76
76
  }>;
77
+ getPullRequestsForUser(input: {
78
+ userId: string;
79
+ } & NumberedPageInput, options?: Options): Promise<{
80
+ pageInfo: {
81
+ hasNextPage: boolean;
82
+ nextPage: number | null;
83
+ };
84
+ data: GitPullRequest[];
85
+ }>;
77
86
  private getPullRequestsForRepoBase;
78
87
  getPullRequestsForRepo(input: {
79
88
  repo: GetRepoInput;
@@ -57,6 +57,9 @@ export interface GitRepository {
57
57
  export interface GitRef {
58
58
  name: string;
59
59
  }
60
+ export interface GitRefWithOID extends GitRef {
61
+ oid: string | null;
62
+ }
60
63
  export interface GitRefWithCommit extends GitRef {
61
64
  commit: GitCommit | null;
62
65
  }
@@ -107,8 +110,8 @@ export interface GitPullRequest {
107
110
  createdDate: Date;
108
111
  updatedDate: Date;
109
112
  closedDate: Date | null;
110
- baseRef: GitRef | null;
111
- headRef: GitRef | null;
113
+ baseRef: GitRefWithOID | null;
114
+ headRef: GitRefWithOID | null;
112
115
  commentCount: number | null;
113
116
  upvoteCount: number | null;
114
117
  commitCount: number | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitkraken/provider-apis",
3
- "version": "0.12.1",
3
+ "version": "0.12.3",
4
4
  "description": "An SDK around different third-party APIs that accepts and returns data in a common format.",
5
5
  "author": "Axosoft, LLC dba GitKraken",
6
6
  "license": "SEE LICENSE IN LICENSE",