@gitkraken/provider-apis 0.25.4 → 0.25.6
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/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Sr=Object.create;var de=Object.defineProperty;var Cr=Object.getOwnPropertyDescriptor;var Dr=Object.getOwnPropertyNames;var Ur=Object.getPrototypeOf,Lr=Object.prototype.hasOwnProperty;var _=(s,t)=>{for(var e in t)de(s,e,{get:t[e],enumerable:!0})},jt=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Dr(t))!Lr.call(s,n)&&n!==e&&de(s,n,{get:()=>t[n],enumerable:!(r=Cr(t,n))||r.enumerable});return s};var Ar=(s,t,e)=>(e=s!=null?Sr(Ur(s)):{},jt(t||!s||!s.__esModule?de(e,"default",{value:s,enumerable:!0}):e,s)),$r=s=>jt(de({},"__esModule",{value:!0}),s);var Ks={};_(Ks,{AzureDevOps:()=>te,AzureDevopsUtils:()=>xe,Bitbucket:()=>re,BitbucketServer:()=>ne,BitbucketServerUtils:()=>Ne,BitbucketUtils:()=>ke,EntityIdentifierProviderType:()=>A,EntityIdentifierUtils:()=>Ke,EntityType:()=>L,EntityVersion:()=>U,GitBuildStatusStage:()=>Ft,GitBuildStatusState:()=>ee,GitDiffLineType:()=>rt,GitHub:()=>oe,GitHubIssueCloseReason:()=>qr,GitHubUtils:()=>Ye,GitIssueState:()=>he,GitLab:()=>ie,GitLabUtils:()=>Ze,GitMergeStrategy:()=>Y,GitProviderUtils:()=>Xe,GitPullRequestMergeableState:()=>F,GitPullRequestReviewState:()=>j,GitPullRequestState:()=>K,Jira:()=>ue,JiraServer:()=>le,JiraUtils:()=>et,PullRequestAsyncStatus:()=>Er,Trello:()=>pe,TrelloUtils:()=>tt,Utils:()=>Vs,default:()=>Js,isFetch:()=>ce});module.exports=$r(Ks);var Ft=(n=>(n.Build="build",n.Production="production",n.Staging="staging",n.Test="test",n))(Ft||{}),ee=(p=>(p.ActionRequired="ACTION_REQUIRED",p.Cancelled="CANCELLED",p.Error="ERROR",p.Failed="FAILED",p.Pending="PENDING",p.Running="RUNNING",p.Skipped="SKIPPED",p.Success="SUCCESS",p.Warning="WARNING",p.OptionalActionRequired="OPTIONAL_ACTION_REQUIRED",p))(ee||{}),Y=(o=>(o.MergeCommit="MERGE_COMMIT",o.Rebase="REBASE",o.RebaseThenMergeCommit="REBASE_THEN_MERGE_COMMIT",o.FastForward="FAST_FORWARD",o.Squash="SQUASH",o))(Y||{}),K=(r=>(r.Open="OPEN",r.Closed="CLOSED",r.Merged="MERGED",r))(K||{}),j=(n=>(n.Approved="APPROVED",n.ChangesRequested="CHANGES_REQUESTED",n.Commented="COMMENTED",n.ReviewRequested="REVIEW_REQUESTED",n))(j||{}),F=(a=>(a.Behind="BEHIND",a.Blocked="BLOCKED",a.Conflicts="CONFLICTS",a.Mergeable="MERGEABLE",a.Unknown="UNKNOWN",a.UnknownAndBlocked="UNKNOWN_AND_BLOCKED",a.Unstable="UNSTABLE",a))(F||{}),rt=(r=>(r.ADDED="ADDED",r.DELETED="DELETED",r.UNMODIFIED="UNMODIFIED",r))(rt||{});var Mt={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},W=s=>!s||s.length===0?null:s.reduce((t,e)=>Mt[e.state]>Mt[t]?e.state:t,"APPROVED");var S=100;var zt=Ar(require("node-fetch")),Ht=globalThis.fetch||zt.default;var Gr=async s=>{let t=s.headers.get("content-type")||"",e=null;if(t.startsWith("application/json")){let n=await s.text();e=n.trim().length>0?JSON.parse(n):null}else if(t.startsWith("text/")||t==="")e=await s.text();else if(t.startsWith("application/vnd.github.raw+json"))e=await s.arrayBuffer();else throw new Error(`Unsupported content-type: ${t}`);let r={body:e,headers:Object.fromEntries(s.headers.entries()),status:s.status,statusText:s.statusText};if(!s.ok){let n=new Error(s.statusText);throw Object.assign(n,{response:r}),n}return r},st=s=>async({url:t,...e})=>{let r=await s(t,e);return Gr(r)};var ce=(s,t=!1)=>s.name==="fetch"||t;var x=class{constructor(t){let e=(t==null?void 0:t.request)||Ht;this.config={...t,request:ce(e,t==null?void 0:t.forceIsFetch)?st(e):e}}updateConfig(t){this.config={...this.config,...t,request:t.request&&ce(t.request,(t==null?void 0:t.forceIsFetch)??this.config.forceIsFetch)?st(t.request):this.config.request}}},Q=class extends x{};var I=(s,t)=>{let e={};return s&&(e.Authorization=`${t?"Basic":"Bearer"} ${s}`),e},Wt=s=>s?s.reduce((t,e)=>(t[e]=!0,t),{}):void 0,J=(s,t,e)=>!s||t.some(r=>s[r])?e:"",Jt=async s=>{var n,o,i;let t=[],e=!0,r;for(;e;){let a=await s(r);t=t.concat(a.data),e=!!((n=a==null?void 0:a.pageInfo)!=null&&n.hasNextPage),r=((o=a==null?void 0:a.pageInfo)==null?void 0:o.endCursor)||((i=a==null?void 0:a.pageInfo)==null?void 0:i.nextPage)}return t};var w=(s,t={})=>I(t.token||s.token,t.isPAT||s.isPAT),Vt=s=>s.url.replace("/_apis/git/repositories/","/_git/").replace(`/${s.repository.project.id}/`,`/${encodeURIComponent(s.repository.project.name)}/`).replace(`/${s.repository.id}/`,`/${encodeURIComponent(s.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var Kt="https://app.vssps.visualstudio.com/_apis",q="https://dev.azure.com",Tr={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Or={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},nt=s=>({id:s.id,name:s.displayName??null,username:(s.uniqueName||s.displayName)??null,email:null,avatarUrl:s.imageUrl??null,url:null}),me=s=>s.startsWith("refs/heads/")?s.replace("refs/heads/",""):s,ge=(s,t)=>{var n;let e=[],r=[];return t.reviewers.forEach(o=>{let i={reviewer:nt(o),state:Or[o.vote??0]||"REVIEW_REQUESTED"};o.isRequired&&e.push(i),r.push(i)}),{id:t.pullRequestId.toString(),title:t.title,number:t.codeReviewId,state:Tr[t.status],isDraft:t.isDraft,commentCount:null,upvoteCount:null,author:nt(t.createdBy),createdDate:new Date(t.creationDate),updatedDate:new Date(t.closedDate||t.creationDate),closedDate:t.closedDate?new Date(t.closedDate):null,mergedDate:t.closedDate&&t.status==="completed"?new Date(t.closedDate):null,repository:{id:t.repository.id,name:t.repository.name,project:t.repository.project.name,owner:{login:s},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:me(t.targetRefName),oid:t.lastMergeTargetCommit.commitId},headRef:{name:me(t.sourceRefName),oid:t.lastMergeSourceCommit.commitId},url:Vt(t),assignees:t.reviewers.map(nt),reviews:r,reviewDecision:W(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((n=t.labels)==null?void 0:n.map(o=>({color:null,description:null,id:o.id,name:o.name})))??[],permissions:null}},Xt=(s,t)=>({id:t.id,name:t.name,namespace:s,project:t.project.name,webUrl:t.webUrl,httpsUrl:t.remoteUrl,sshUrl:t.sshUrl,defaultBranch:t.defaultBranch?{name:me(t.defaultBranch)}:null,permission:null}),xr=(s,t,e,r)=>{var l,p,d,g,c,m;let n=e.fields,o=n["System.AssignedTo"],i=n["System.State"],a=n["System.WorkItemType"],u;return i&&a&&(u=(l=r[a])==null?void 0:l[i]),{id:e.id.toString(),number:e.id.toString(),title:n["System.Title"],commentCount:n["System.CommentCount"],author:{avatarUrl:((d=(p=n["System.CreatedBy"]._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,email:null,id:n["System.CreatedBy"].id,name:n["System.CreatedBy"].uniqueName??null,username:n["System.CreatedBy"].displayName??null,url:null},closedDate:n["Microsoft.VSTS.Common.ClosedDate"]?new Date(n["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(n["System.CreatedDate"]),updatedDate:new Date(n["System.ChangedDate"]),url:e._links.html.href,assignees:o?[{avatarUrl:((c=(g=o._links)==null?void 0:g.avatar)==null?void 0:c.href)??null,email:null,id:o.id,name:o.uniqueName??null,username:o.displayName??null,url:null}]:[],description:null,state:{name:(u==null?void 0:u.title)||i,color:null},type:n["System.WorkItemType"],repository:null,project:{namespace:s,name:t,resourceId:null,key:null,id:null},upvoteCount:0,labels:((m=e.fields["System.Tags"])==null?void 0:m.split(";").map(h=>({color:null,description:null,id:null,name:h.trim()})))??[]}},te=class extends x{async getCurrentUser(t={},e={}){if(e.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let r=await this.config.request({url:`${Kt}/profile/profiles/me`,headers:w(this.config,e)});return{data:{id:r.body.id,name:r.body.displayName,username:r.body.displayName,email:r.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(t,e={}){let n=(await this.config.request({url:`${q}/${encodeURIComponent(t.namespace)}/_apis/ConnectionData`,headers:w(this.config,e)})).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(t,e={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${q}/${encodeURIComponent(t.repo.namespace)}/${encodeURIComponent(t.repo.project)}/_apis/git/repositories/${encodeURIComponent(t.repo.name)}/commits/${t.oid}`,headers:w(this.config,e)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(t,e={}){return{data:(await this.config.request({url:`${Kt}/accounts?memberId=${t.userId}&api-version=6.0`,headers:w(this.config,e)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(t,e={}){let r=new URL(`${q}/${encodeURIComponent(t.namespace)}/_apis/projects`);r.searchParams.set("$top",S.toString()),t.cursor&&r.searchParams.set("$skip",t.cursor);let n=await this.config.request({url:r.toString(),headers:w(this.config,e)}),o=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:n.body.value.map(i=>({id:i.id,name:i.name,namespace:t.namespace}))}}async getAzureProjectScopeDescriptor(t,e={}){let{namespace:r,projectId:n}=t;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:w(this.config,e)})).body.value}}}async getAzureGraphAccountsForAzureProject(t,e={}){let{namespace:r,projectScopeDescriptor:n,cursor:o}=t,i=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/users`);n&&i.searchParams.set("scopeDescriptor",n),o&&i.searchParams.set("continuationToken",o);let a=await this.config.request({url:i.toString(),headers:w(this.config,e)}),u=a.headers["x-ms-continuationtoken"];return{pageInfo:{endCursor:u||null,hasNextPage:!!u},data:a.body.value.map(l=>{var p,d,g,c;return{avatarUrl:((d=(p=l._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,descriptor:l.descriptor??null,email:l.mailAddress??null,name:l.displayName??null,storageKeyURL:((c=(g=l._links)==null?void 0:g.storageKey)==null?void 0:c.href)??null,username:l.displayName??null}})}}async getAccountFromAzureGraphAccount(t,e={}){let{azureGraphAccount:r}=t;if(!r.storageKeyURL)throw new Error("Expected 'storageKeyURL' to not be null for 'azureGraphAccount'");let n=await this.config.request({url:r.storageKeyURL,headers:w(this.config,e)});return{data:{avatarUrl:r.avatarUrl,email:r.email,id:n.body.value,name:r.name,username:r.username,url:null}}}async getAccountsFromAzureGraphAccounts(t,e={}){let r=[];for(let n of t.azureGraphAccounts){let o=await this.getAccountFromAzureGraphAccount({azureGraphAccount:n},e);r.push(o.data)}return{data:r}}async getRepo(t,e={}){if(!t.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=await this.config.request({url:`${q}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/git/repositories/${encodeURIComponent(t.name)}`,headers:w(this.config,e)});return{data:Xt(t.namespace,r.body)}}async getRepos(t,e={}){let r=[],n=[];return await Promise.all(t.map(async o=>{try{let i=await this.getRepo(o,e);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForAzureProject(t,e={}){if(!t.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${q}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/git/repositories`,headers:w(this.config,e)})).body.value.map(n=>Xt(t.namespace,n))}}async getRefs(t,e,r={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${q}/${encodeURIComponent(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/refs`);n.searchParams.set("filter",t),n.searchParams.set("$top",S.toString()),e.cursor&&n.searchParams.set("continuationToken",e.cursor);let o=await this.config.request({url:n.toString(),headers:w(this.config,r)}),i=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!i,endCursor:i||null},data:o.body.value.map(a=>({name:me(a.name),commit:{oid:a.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(t,e={}){return this.getRefs("heads",t,e)}async getTags(t,e={}){return this.getRefs("tags",t,e)}async getPullRequestsForRepoBase(t,e={},r=100){let{page:n,repo:o,assigneeLogins:i,authorLogin:a}=t||{},u=n||1;if(!o.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return i&&i.length&&(l+=`&searchCriteria.reviewerId=${i[0]}`),a&&(l+=`&searchCriteria.creatorId=${a}`),await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${r}&%24skip=${(u-1)*r}`,headers:w(this.config,e)})}async getPullRequestsForRepo(t,e={}){let n=t.page||1,o=await this.getPullRequestsForRepoBase(t,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(i=>ge(t.repo.namespace,i))}}async getPullRequestsForRepos(t,e={}){if(!t.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:r}=t||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...t},e)).body.value.forEach(a=>{n.push(ge(o.namespace,a))})}catch(i){if(i.statusCode!==404&&i.statusCode!==401)throw i}})),{data:n}}async getPullRequestsForProjectBase(t,e={},r=100){let{namespace:n,project:o,page:i,assigneeLogins:a,authorLogin:u}=t,l=i||1,p=new URL(`${e.baseUrl||q}/${encodeURIComponent(n)}/${encodeURIComponent(o)}/_apis/git/pullRequests`);return p.searchParams.set("searchCriteria.status","1"),p.searchParams.set("$top",r.toString()),p.searchParams.set("$skip",((l-1)*r).toString()),a&&a.length&&p.searchParams.set("searchCriteria.reviewerId",a[0]),u&&p.searchParams.set("searchCriteria.creatorId",u),await this.config.request({url:p.toString(),headers:w(this.config,e)})}async getPullRequestsForProject(t,e={}){let n=t.page||1,o=await this.getPullRequestsForProjectBase(t,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(i=>ge(t.namespace,i))}}async getPullRequestsForProjects(t,e={}){let{projects:r}=t||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForProjectBase({...o,...t},e)).body.value.forEach(a=>{n.push(ge(o.namespace,a))})}catch(i){if(i.statusCode!==404&&i.statusCode!==401)throw i}})),{data:n}}async getAzurePullRequestLastMergeStatus(t,e={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:o},pullRequestId:i}=t,a=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${i}?includeCommits=true?api-version=6.0`,headers:{...w(this.config,e)}});if(!a.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:a.body.mergeStatus}}async updatePullRequest(t,e,r){return await this.config.request({method:"PATCH",url:`${r.baseUrl||q}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}?api-version=6.0`,body:e,headers:{...w(this.config,r),"Content-Type":"application/json"}})}async closePullRequest(t,e={}){let{pullRequest:r}=t,n={status:"abandoned"};if(!(await this.updatePullRequest(r,JSON.stringify(n),e)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(t,e={}){var u;let{pullRequest:r,mergeStrategy:n}=t,o;switch(n){case"MERGE_COMMIT":{o="noFastForward";break}case"REBASE":{o="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{o="rebaseMerge";break}case"SQUASH":{o="squash";break}}let i={completionOptions:{mergeStrategy:o},lastMergeSourceCommit:{commitId:(u=r.headRef)==null?void 0:u.oid},status:"completed"};if(!(await this.updatePullRequest(r,JSON.stringify(i),e)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(t,e={}){let{pullRequest:r,label:n}=t;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o={name:n.name};if(!(await this.config.request({method:"POST",url:`${e.baseUrl||q}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/labels?api-version=6.0`,body:JSON.stringify(o),headers:{...w(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(t,e={}){let{pullRequest:r,label:n}=t;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');await this.config.request({method:"DELETE",url:`${e.baseUrl||q}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/labels/${encodeURIComponent(n.name)}?api-version=6.0`,headers:{...w(this.config,e)}})}async setPullRequestLabels(t,e={}){let{pullRequest:r,labels:n}=t;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o=r.labels;if(!o)throw new Error('Azure DevOps requires "labels" for this function.');for(let i of n)o.find(a=>a.id===i.id)||await this.addPullRequestLabel({pullRequest:r,label:i},e);for(let i of o)n.find(a=>i.id===a.id)||await this.removePullRequestLabel({pullRequest:r,label:i},e)}async setPullRequestAsDraft(t,e={}){let{pullRequest:r,isDraft:n}=t,o={isDraft:n};if(!(await this.updatePullRequest(r,JSON.stringify(o),e)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(t,e={}){let{pullRequest:r,reviewer:n,isRequired:o}=t,i={id:n.id,isRequired:o};if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||q}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/reviewers/${n.id}?api-version=6.0`,body:JSON.stringify(i),headers:{...w(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(t,e={}){let{pullRequest:r,reviewer:n}=t;await this.config.request({method:"DELETE",url:`${e.baseUrl||q}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/reviewers/${n.id}?api-version=6.0`,headers:{...w(this.config,e),Accept:"application/json"}})}async setPullRequestReviewers(t,e={}){let{pullRequest:r,reviewers:n}=t;for(let o of n)r.assignees.find(i=>i.id===o.id)||await this.addPullRequestReviewer({pullRequest:r,reviewer:o,isRequired:!0},e);for(let o of r.assignees)n.find(i=>o.id===i.id)||await this.removePullRequestReviewer({pullRequest:r,reviewer:o},e)}async getIssuesForAzureProject(t,e={}){let{page:r,assigneeLogins:n,authorLogin:o,mentionLogin:i,labelNames:a,statusByWorkItemIdByStatusId:u}=t||{},l=r||1,p=200,d=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&d.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),n&&n[0]&&d.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),i&&d.push("[System.Id] IN (@recentMentions)"),a&&a.forEach(R=>d.push(`[System.Tags] Contains '${R}'`));let g=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${d.join(" AND ")} order by [System.CreatedDate] desc`,c=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:g}),method:"POST",headers:{...w(this.config,e),"Content-Type":"application/json"}}),m=c.body.workItems.slice((l-1)*p,p*l).map(R=>R.id);if(m.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let h=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:m,$expand:"Links"}),method:"POST",headers:{...w(this.config,e),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:c.body.workItems.length>p*l,nextPage:l+1},data:h.body.value.map(R=>xr(t.namespace,t.project,R,u||{}))}}async updateIssue(t,e,r={}){return await this.config.request({method:"PATCH",url:`${r.baseUrl||q}/${encodeURIComponent(t.project.namespace)}/${encodeURIComponent(t.project.name)}/_apis/wit/workitems/${t.id}?api-version=6.0`,body:JSON.stringify(e),headers:{...w(this.config,r),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(t,e={}){var a;let{issue:r,status:n}=t,o=[{op:"add",path:"/fields/System.State",value:n.name}];if(!((a=(await this.updateIssue(r,o,e)).body.fields)!=null&&a["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(t,e={}){var a;let{issue:r,assignee:n}=t,o=[{op:"add",path:"/fields/System.AssignedTo",value:(n==null?void 0:n.name)??""}];if(!((a=(await this.updateIssue(r,o,e)).body.fields)!=null&&a["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(t,e={}){var u;let{issue:r,labels:n}=t,i=[{op:"replace",path:"/fields/System.Tags",value:n.map(l=>l.name).join(";")}];if(!((u=(await this.updateIssue(r,i,e)).body.fields)!=null&&u["System.Tags"]))throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(t,e={}){if(!t.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n}=t;return{data:(await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...w(this.config,e)}})).body.value}}async getLabelsForProject(t,e={}){let{namespace:r,project:n}=t;return{data:(await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...w(this.config,e)}})).body.value.map(i=>({color:null,description:null,id:i.id,name:i.name,url:i.url}))}}};var G=(s,t={})=>I(t.token||s.token,t.isPAT||s.isPAT);var k="https://api.bitbucket.org/2.0",kr={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},Zt=s=>({id:s.uuid,name:s.display_name||s.nickname,username:s.nickname||s.display_name,email:null,avatarUrl:s.links.avatar.href,url:s.links.html.href}),Yt=s=>{var t,e;return{id:s.uuid,namespace:s.workspace.slug,name:s.slug,webUrl:s.links.html.href,httpsUrl:((t=s.links.clone.find(r=>r.name==="https"))==null?void 0:t.href)??null,sshUrl:((e=s.links.clone.find(r=>r.name==="ssh"))==null?void 0:e.href)??null,defaultBranch:{name:s.mainbranch.name},permission:null}},ot=s=>{let t=s.id;return{id:t.toString(),title:s.title,number:t,state:kr[s.state],isDraft:!1,commentCount:s.comment_count,upvoteCount:null,author:Zt(s.author),createdDate:new Date(s.created_on),updatedDate:new Date(s.updated_on),closedDate:null,mergedDate:null,repository:{id:s.destination.repository.uuid,name:s.destination.repository.name,owner:{login:s.destination.repository.full_name.split("/")[0]},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:s.destination.branch.name,oid:s.destination.commit.hash},headRef:{name:s.source.branch.name,oid:s.source.commit.hash},url:s.links.html.href,assignees:null,reviews:null,reviewDecision:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",permissions:null}},re=class extends x{async refreshToken(t){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 ${t.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${t.refreshToken}`})).body}}async getCurrentUser(t={},e={}){let r=await this.config.request({url:`${k}/user`,headers:G(this.config,e)});return{data:Zt(r.body)}}async getUserForCommit(t,e={}){var i;let n=(await this.config.request({url:`${k}/repositories/${t.repo.namespace}/${t.repo.name}/commit/${t.oid}`,headers:G(this.config,e)})).body.author,o=n.raw.match(/([^<]+)<(.+)>/);return{data:{name:o?o[1].trim():null,email:o?o[2]:null,avatarUrl:((i=n.user)==null?void 0:i.links.avatar.href)||null}}}async getRepo(t,e={}){let r=await this.config.request({url:`${k}/repositories/${t.namespace}/${t.name}`,headers:G(this.config,e)});return{data:Yt(r.body)}}async getRepos(t,e={}){let r=[],n=[];return await Promise.all(t.map(async o=>{try{let i=await this.getRepo(o,e);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForCurrentUser(t,e={}){let r=new URL(`${k}/repositories`);r.searchParams.set("role","member"),r.searchParams.set("pagelen",S.toString()),t.cursor&&r.searchParams.set("after",t.cursor);let n=await this.config.request({url:r.toString(),headers:G(this.config,e)}),o=!!n.body.next,i=null;return n.body.next&&(i=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:i},data:n.body.values.map(Yt)}}async getBranches(t,e={}){var i;let r=new URL(`${k}/repositories/${t.repo.namespace}/${t.repo.name}/refs/branches`);r.searchParams.set("page",((i=t.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen",S.toString());let n=await this.config.request({url:r.toString(),headers:G(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(a=>{let u=new Date(a.target.date);return{name:a.name,commit:{oid:a.target.hash,authoredDate:u,committedDate:u}}})}}async getTags(t,e={}){let r=new URL(`${k}/repositories/${t.repo.namespace}/${t.repo.name}/refs/tags`);r.searchParams.set("pagelen",S.toString()),t.cursor&&r.searchParams.set("page",t.cursor);let n=await this.config.request({url:r.toString(),headers:G(this.config,e)}),o=!!n.body.next,i=null;return n.body.next&&(i=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:i},data:n.body.values.map(a=>{let u=new Date(a.target.date);return{name:a.name,commit:{oid:a.target.hash,authoredDate:u,committedDate:u}}})}}async getPullRequestsForUser(t,e={}){var i;let r=new URL(`${k}/pullrequests/${t.userId}`);r.searchParams.set("page",((i=t.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen","50");let n=await this.config.request({url:r.toString(),headers:G(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(ot)}}async getPullRequestsForRepoBase(t,e={}){var n;let r=new URL(`${k}/repositories/${encodeURI(t.repo.namespace)}/${encodeURI(t.repo.name)}/pullrequests?state=OPEN`);return r.searchParams.set("page",((n=t.page)==null?void 0:n.toString())||"1"),r.searchParams.set("pagelen","50"),await this.config.request({url:r.toString(),headers:G(this.config,e)})}async getPullRequestsForRepo(t,e={}){let r=[],n=await this.getPullRequestsForRepoBase(t,e);n.body.values.forEach(i=>{if(t.authorLogin&&i.author.uuid!==t.authorLogin)return null;r.push(ot(i))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:r}}async getPullRequestsForRepos(t,e={}){let r=[];return await Promise.all(t.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...t},e)).body.values.forEach(i=>{if(t.authorLogin&&i.author.uuid!==t.authorLogin)return null;r.push(ot(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async closePullRequest(t,e={}){let{pullRequest:r}=t;if(!(await this.config.request({method:"POST",url:`${k}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/decline`,headers:G(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(t,e={}){let{pullRequest:r,mergeStrategy:n}=t,o;switch(n){case"MERGE_COMMIT":{o="merge_commit";break}case"FAST_FORWARD":{o="fast_forward";break}case"SQUASH":{o="squash";break}}let i={merge_strategy:o,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${k}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/merge`,body:JSON.stringify(i),headers:{...G(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(t,e={}){let{pullRequest:r,reviewers:n}=t,o={reviewers:n.map(a=>{if(a.username)throw new Error('Bitbucket reviewer requires "username" for this function.');return{username:a.username}})};if(!(await this.config.request({method:"PUT",url:`${k}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}`,body:JSON.stringify(o),headers:{...G(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var it=s=>({name:s.displayName,email:s.emailAddress,avatarUrl:s.avatarUrl??null,id:s.id.toString(),username:s.name,url:s.links.self[0].href}),se=s=>{var u,l,p,d,g,c;let t={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},e={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},r=s.reviewers.map(m=>({reviewer:it(m.user),state:e[m.status]})),n=((u=s.toRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:u.href)??null,o=((l=s.toRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:l.href)??null;o||(o=((p=s.toRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:p.href)??null);let i=((d=s.fromRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:d.href)??null,a=((g=s.fromRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:g.href)??null;return a||(a=((c=s.fromRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:c.href)??null),{id:s.id.toString(),number:s.id,title:s.title,url:s.links.self[0].href,state:t[s.state],isDraft:!1,createdDate:new Date(s.createdDate),updatedDate:new Date(s.updatedDate),closedDate:s.closedDate?new Date(s.closedDate):null,mergedDate:s.state=="MERGED"&&s.closedDate?new Date(s.closedDate):null,baseRef:{name:s.toRef.displayId,oid:s.toRef.latestCommit},headRef:{name:s.fromRef.displayId,oid:s.fromRef.latestCommit},commentCount:s.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:it(s.author.user),assignees:null,reviews:r,reviewDecision:W(r),repository:{id:s.toRef.repository.id.toString(),name:s.toRef.repository.name,owner:{login:s.toRef.repository.project.key},remoteInfo:o&&n?{cloneUrlHTTPS:o,cloneUrlSSH:n}:null},headRepository:{id:s.fromRef.repository.id.toString(),name:s.fromRef.repository.name,owner:{login:s.fromRef.repository.project.key},remoteInfo:a&&i?{cloneUrlHTTPS:a,cloneUrlSSH:i}:null},headCommit:null,mergeableState:"UNKNOWN",permissions:null,version:s.version}},er=s=>{var t,e,r;return{id:s.id.toString(),namespace:s.project.key,name:s.slug,webUrl:((t=s.links.self[0])==null?void 0:t.href)??null,httpsUrl:((e=s.links.clone.find(n=>n.name==="https"||n.name==="http"))==null?void 0:e.href)??null,sshUrl:((r=s.links.clone.find(n=>n.name==="ssh"))==null?void 0:r.href)??null,defaultBranch:null,permission:null}},ne=class extends Q{getBaseUrl(t){let e=t.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(t){return I(t.token||this.config.token)}async getCurrentUser(t={},e={}){let r=await this.config.request({url:`${this.getBaseUrl(e)}/users?limit=2`,headers:this.getRequestHeaders(e)}),{headers:{"x-auserid":n,"x-ausername":o}}=r,i=n?parseInt(n,10):null,a=decodeURIComponent(o),l=(await this.config.request({url:`${this.getBaseUrl(e)}/users?filter=${o}&avatarSize=64`,headers:this.getRequestHeaders(e)})).body.values.find(({emailAddress:p,id:d,name:g,slug:c})=>i?i===d:a===g||a===p||a===c);if(!l)throw new Error("Could not find current Bitbucket Server user");return{data:it(l)}}async getRepo(t,e={}){let r=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${t.namespace}/repos/${t.name}`,headers:this.getRequestHeaders(e)});return{data:er(r.body)}}async getRepos(t,e={}){let r=[],n=[];return await Promise.all(t.map(async o=>{try{let i=await this.getRepo(o,e);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForCurrentUser(t,e={}){let r=t.page??0,n=await this.config.request({url:`${this.getBaseUrl(e)}/repos?start=${r}`,headers:this.getRequestHeaders(e)});return{pageInfo:{hasNextPage:!n.body.isLastPage,nextPage:n.body.nextPageStart},data:n.body.values.map(er)}}async getPullRequestsForRepoBase(t,e={}){var n;let r=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(t.repo.namespace)}/repos/${encodeURI(t.repo.name)}/pull-requests?state=OPEN`);return r.searchParams.set("start",((n=t.page)==null?void 0:n.toString())||"0"),r.searchParams.set("limit","50"),await this.config.request({url:r.toString(),headers:this.getRequestHeaders(e)})}async getPullRequestsForRepo(t,e={}){let r=[],n=await this.getPullRequestsForRepoBase(t,e);n.body.values.forEach(i=>{if(t.authorLogin&&i.author.user.name!==t.authorLogin)return null;r.push(se(i))});let o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:r}}async getPullRequestsForRepos(t,e={}){let r=[];return await Promise.all(t.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...t},e)).body.values.forEach(i=>{if(t.authorLogin&&i.author.user.name!==t.authorLogin)return null;r.push(se(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async getPullRequestsForCurrentUser(t,e={}){var i;let r=new URL(`${this.getBaseUrl(e)}/dashboard/pull-requests`);r.searchParams.set("state","OPEN"),r.searchParams.set("start",((i=t.page)==null?void 0:i.toString())||"0"),r.searchParams.set("limit","50");let n=await this.config.request({url:r.toString(),headers:this.getRequestHeaders(e)}),o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:n.body.values.map(se)}}async closePullRequest(t,e={}){let{pullRequest:r}=t;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/decline`,body:JSON.stringify({version:r.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(t,e={}){let{pullRequest:r,mergeStrategyId:n}=t;if(t.mergeStrategy)throw new Error('Bitbucket Server uses "mergeStrategyId" instead of "mergeStrategy".');if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/merge`,body:JSON.stringify({strategyId:n,version:r.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(t={}){let e=await this.config.request({url:`${this.getBaseUrl(t)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(t),"Content-Type":"application/json"}});return{data:{defaultStrategy:e.body.mergeConfig.defaultStrategy,strategies:e.body.mergeConfig.strategies}}}async setPullRequestReviewers(t,e={}){let{pullRequest:r,reviewers:n}=t;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');let o={reviewers:n.map(a=>{if(a.username)throw new Error('Bitbucket Server reviewer requires "username" for this function.');return{user:{name:a.username}}}),version:r.version};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}`,body:JSON.stringify(o),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var ir=require("js-base64");var he=(e=>(e.Open="OPEN",e.Closed="CLOSED",e))(he||{});var Nr={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0]},tr=15,rr=100,D=s=>!!s,fe=(s,t)=>{let e=Nr[t];for(let r=0;r<3;r++){if(s[r]>e[r])return!0;if(s[r]<e[r])return!1}return!0},Re="https://api.github.com",_r=`${Re}/graphql`,ye=`
|
|
1
|
+
"use strict";var Ur=Object.create;var ce=Object.defineProperty;var Ar=Object.getOwnPropertyDescriptor;var Lr=Object.getOwnPropertyNames;var $r=Object.getPrototypeOf,Gr=Object.prototype.hasOwnProperty;var _=(s,t)=>{for(var e in t)ce(s,e,{get:t[e],enumerable:!0})},zt=(s,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Lr(t))!Gr.call(s,n)&&n!==e&&ce(s,n,{get:()=>t[n],enumerable:!(r=Ar(t,n))||r.enumerable});return s};var Tr=(s,t,e)=>(e=s!=null?Ur($r(s)):{},zt(t||!s||!s.__esModule?ce(e,"default",{value:s,enumerable:!0}):e,s)),Or=s=>zt(ce({},"__esModule",{value:!0}),s);var on={};_(on,{AzureDevOps:()=>re,AzureDevopsUtils:()=>Ne,Bitbucket:()=>se,BitbucketServer:()=>oe,BitbucketServerUtils:()=>Be,BitbucketUtils:()=>_e,EntityIdentifierProviderType:()=>C,EntityIdentifierUtils:()=>Ye,EntityType:()=>L,EntityVersion:()=>A,GitBuildStatusStage:()=>Wt,GitBuildStatusState:()=>te,GitDiffLineType:()=>nt,GitHub:()=>ie,GitHubIssueCloseReason:()=>Dr,GitHubUtils:()=>et,GitIssueState:()=>Ie,GitLab:()=>ae,GitLabUtils:()=>tt,GitMergeStrategy:()=>Z,GitProviderUtils:()=>Ze,GitPullRequestMergeableState:()=>F,GitPullRequestReviewState:()=>j,GitPullRequestState:()=>K,Jira:()=>le,JiraServer:()=>pe,JiraUtils:()=>rt,PullRequestAsyncStatus:()=>Cr,Trello:()=>de,TrelloUtils:()=>st,Utils:()=>nn,default:()=>sn,isFetch:()=>me});module.exports=Or(on);var Wt=(n=>(n.Build="build",n.Production="production",n.Staging="staging",n.Test="test",n))(Wt||{}),te=(p=>(p.ActionRequired="ACTION_REQUIRED",p.Cancelled="CANCELLED",p.Error="ERROR",p.Failed="FAILED",p.Pending="PENDING",p.Running="RUNNING",p.Skipped="SKIPPED",p.Success="SUCCESS",p.Warning="WARNING",p.OptionalActionRequired="OPTIONAL_ACTION_REQUIRED",p))(te||{}),Z=(o=>(o.MergeCommit="MERGE_COMMIT",o.Rebase="REBASE",o.RebaseThenMergeCommit="REBASE_THEN_MERGE_COMMIT",o.FastForward="FAST_FORWARD",o.Squash="SQUASH",o))(Z||{}),K=(r=>(r.Open="OPEN",r.Closed="CLOSED",r.Merged="MERGED",r))(K||{}),j=(n=>(n.Approved="APPROVED",n.ChangesRequested="CHANGES_REQUESTED",n.Commented="COMMENTED",n.ReviewRequested="REVIEW_REQUESTED",n))(j||{}),F=(a=>(a.Behind="BEHIND",a.Blocked="BLOCKED",a.Conflicts="CONFLICTS",a.Mergeable="MERGEABLE",a.Unknown="UNKNOWN",a.UnknownAndBlocked="UNKNOWN_AND_BLOCKED",a.Unstable="UNSTABLE",a))(F||{}),nt=(r=>(r.ADDED="ADDED",r.DELETED="DELETED",r.UNMODIFIED="UNMODIFIED",r))(nt||{});var Ht={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},H=s=>!s||s.length===0?null:s.reduce((t,e)=>Ht[e.state]>Ht[t]?e.state:t,"APPROVED"),ge=(s,t)=>s.name||s.username||s.email||t,X=s=>{let t=Object.values(s).map(e=>e.name).sort((e,r)=>e.localeCompare(r));return Object.values(s).forEach(e=>{e.priority!==-1&&(e.priority=t.indexOf(e.name))}),s};var S=100;var Jt=Tr(require("node-fetch")),Vt=globalThis.fetch||Jt.default;var xr=async s=>{let t=s.headers.get("content-type")||"",e=null;if(t.startsWith("application/json")){let n=await s.text();e=n.trim().length>0?JSON.parse(n):null}else if(t.startsWith("text/")||t==="")e=await s.text();else if(t.startsWith("application/vnd.github.raw+json"))e=await s.arrayBuffer();else throw new Error(`Unsupported content-type: ${t}`);let r={body:e,headers:Object.fromEntries(s.headers.entries()),status:s.status,statusText:s.statusText};if(!s.ok){let n=new Error(s.statusText);throw Object.assign(n,{response:r}),n}return r},ot=s=>async({url:t,...e})=>{let r=await s(t,e);return xr(r)};var me=(s,t=!1)=>s.name==="fetch"||t;var x=class{constructor(t){let e=(t==null?void 0:t.request)||Vt;this.config={...t,request:me(e,t==null?void 0:t.forceIsFetch)?ot(e):e}}updateConfig(t){this.config={...this.config,...t,request:t.request&&me(t.request,(t==null?void 0:t.forceIsFetch)??this.config.forceIsFetch)?ot(t.request):this.config.request}}},B=class extends x{};var I=(s,t)=>{let e={};return s&&(e.Authorization=`${t?"Basic":"Bearer"} ${s}`),e},Kt=s=>s?s.reduce((t,e)=>(t[e]=!0,t),{}):void 0,J=(s,t,e)=>!s||t.some(r=>s[r])?e:"",Xt=async s=>{var n,o,i;let t=[],e=!0,r;for(;e;){let a=await s(r);t=t.concat(a.data),e=!!((n=a==null?void 0:a.pageInfo)!=null&&n.hasNextPage),r=((o=a==null?void 0:a.pageInfo)==null?void 0:o.endCursor)||((i=a==null?void 0:a.pageInfo)==null?void 0:i.nextPage)}return t};var P=(s,t={})=>I(t.token||s.token,t.isPAT||s.isPAT),Yt=s=>s.url.replace("/_apis/git/repositories/","/_git/").replace(`/${s.repository.project.id}/`,`/${encodeURIComponent(s.repository.project.name)}/`).replace(`/${s.repository.id}/`,`/${encodeURIComponent(s.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var Zt="https://app.vssps.visualstudio.com/_apis",q="https://dev.azure.com",kr={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Nr={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},it=s=>({id:s.id,name:s.displayName??null,username:(s.uniqueName||s.displayName)??null,email:null,avatarUrl:s.imageUrl??null,url:null}),fe=s=>s.startsWith("refs/heads/")?s.replace("refs/heads/",""):s,he=(s,t)=>{var n;let e=[],r=[];return t.reviewers.forEach(o=>{let i={reviewer:it(o),state:Nr[o.vote??0]||"REVIEW_REQUESTED"};o.isRequired&&e.push(i),r.push(i)}),{id:t.pullRequestId.toString(),title:t.title,number:t.codeReviewId,state:kr[t.status],isDraft:t.isDraft,commentCount:null,upvoteCount:null,author:it(t.createdBy),createdDate:new Date(t.creationDate),updatedDate:new Date(t.closedDate||t.creationDate),closedDate:t.closedDate?new Date(t.closedDate):null,mergedDate:t.closedDate&&t.status==="completed"?new Date(t.closedDate):null,repository:{id:t.repository.id,name:t.repository.name,project:t.repository.project.name,owner:{login:s},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:fe(t.targetRefName),oid:t.lastMergeTargetCommit.commitId},headRef:{name:fe(t.sourceRefName),oid:t.lastMergeSourceCommit.commitId},url:Yt(t),assignees:t.reviewers.map(it),reviews:r,reviewDecision:H(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((n=t.labels)==null?void 0:n.map(o=>({color:null,description:null,id:o.id,name:o.name})))??[],permissions:null}},er=(s,t)=>({id:t.id,name:t.name,namespace:s,project:t.project.name,webUrl:t.webUrl,httpsUrl:t.remoteUrl,sshUrl:t.sshUrl,defaultBranch:t.defaultBranch?{name:fe(t.defaultBranch)}:null,permission:null}),_r=(s,t,e,r)=>{var l,p,d,c,g,m;let n=e.fields,o=n["System.AssignedTo"],i=n["System.State"],a=n["System.WorkItemType"],u;return i&&a&&(u=(l=r[a])==null?void 0:l[i]),{id:e.id.toString(),number:e.id.toString(),title:n["System.Title"],commentCount:n["System.CommentCount"],author:{avatarUrl:((d=(p=n["System.CreatedBy"]._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,email:null,id:n["System.CreatedBy"].id,name:n["System.CreatedBy"].uniqueName??null,username:n["System.CreatedBy"].displayName??null,url:null},closedDate:n["Microsoft.VSTS.Common.ClosedDate"]?new Date(n["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(n["System.CreatedDate"]),updatedDate:new Date(n["System.ChangedDate"]),url:e._links.html.href,assignees:o?[{avatarUrl:((g=(c=o._links)==null?void 0:c.avatar)==null?void 0:g.href)??null,email:null,id:o.id,name:o.uniqueName??null,username:o.displayName??null,url:null}]:[],description:null,state:{name:(u==null?void 0:u.title)||i,color:null},type:n["System.WorkItemType"],repository:null,project:{namespace:s,name:t,resourceId:null,key:null,id:null},upvoteCount:0,labels:((m=e.fields["System.Tags"])==null?void 0:m.split(";").map(h=>({color:null,description:null,id:null,name:h.trim()})))??[]}},re=class extends x{async getCurrentUser(t={},e={}){if(e.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let r=await this.config.request({url:`${Zt}/profile/profiles/me`,headers:P(this.config,e)});return{data:{id:r.body.id,name:r.body.displayName,username:r.body.displayName,email:r.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(t,e={}){let n=(await this.config.request({url:`${q}/${encodeURIComponent(t.namespace)}/_apis/ConnectionData`,headers:P(this.config,e)})).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(t,e={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${q}/${encodeURIComponent(t.repo.namespace)}/${encodeURIComponent(t.repo.project)}/_apis/git/repositories/${encodeURIComponent(t.repo.name)}/commits/${t.oid}`,headers:P(this.config,e)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(t,e={}){return{data:(await this.config.request({url:`${Zt}/accounts?memberId=${t.userId}&api-version=6.0`,headers:P(this.config,e)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(t,e={}){let r=new URL(`${q}/${encodeURIComponent(t.namespace)}/_apis/projects`);r.searchParams.set("$top",S.toString()),t.cursor&&r.searchParams.set("$skip",t.cursor);let n=await this.config.request({url:r.toString(),headers:P(this.config,e)}),o=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:n.body.value.map(i=>({id:i.id,name:i.name,namespace:t.namespace}))}}async getAzureProjectScopeDescriptor(t,e={}){let{namespace:r,projectId:n}=t;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:P(this.config,e)})).body.value}}}async getAzureGraphAccountsForAzureProject(t,e={}){let{namespace:r,projectScopeDescriptor:n,cursor:o}=t,i=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/users`);n&&i.searchParams.set("scopeDescriptor",n),o&&i.searchParams.set("continuationToken",o);let a=await this.config.request({url:i.toString(),headers:P(this.config,e)}),u=a.headers["x-ms-continuationtoken"];return{pageInfo:{endCursor:u||null,hasNextPage:!!u},data:a.body.value.map(l=>{var p,d,c,g;return{avatarUrl:((d=(p=l._links)==null?void 0:p.avatar)==null?void 0:d.href)??null,descriptor:l.descriptor??null,email:l.mailAddress??null,name:l.displayName??null,storageKeyURL:((g=(c=l._links)==null?void 0:c.storageKey)==null?void 0:g.href)??null,username:l.displayName??null}})}}async getAccountFromAzureGraphAccount(t,e={}){let{azureGraphAccount:r}=t;if(!r.storageKeyURL)throw new Error("Expected 'storageKeyURL' to not be null for 'azureGraphAccount'");let n=await this.config.request({url:r.storageKeyURL,headers:P(this.config,e)});return{data:{avatarUrl:r.avatarUrl,email:r.email,id:n.body.value,name:r.name,username:r.username,url:null}}}async getAccountsFromAzureGraphAccounts(t,e={}){let r=[];for(let n of t.azureGraphAccounts){let o=await this.getAccountFromAzureGraphAccount({azureGraphAccount:n},e);r.push(o.data)}return{data:r}}async getRepo(t,e={}){if(!t.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=await this.config.request({url:`${q}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/git/repositories/${encodeURIComponent(t.name)}`,headers:P(this.config,e)});return{data:er(t.namespace,r.body)}}async getRepos(t,e={}){let r=[],n=[];return await Promise.all(t.map(async o=>{try{let i=await this.getRepo(o,e);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForAzureProject(t,e={}){if(!t.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${q}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/git/repositories`,headers:P(this.config,e)})).body.value.map(n=>er(t.namespace,n))}}async getRefs(t,e,r={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${q}/${encodeURIComponent(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/refs`);n.searchParams.set("filter",t),n.searchParams.set("$top",S.toString()),e.cursor&&n.searchParams.set("continuationToken",e.cursor);let o=await this.config.request({url:n.toString(),headers:P(this.config,r)}),i=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!i,endCursor:i||null},data:o.body.value.map(a=>({name:fe(a.name),commit:{oid:a.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(t,e={}){return this.getRefs("heads",t,e)}async getTags(t,e={}){return this.getRefs("tags",t,e)}async getPullRequestsForRepoBase(t,e={},r=100){let{page:n,repo:o,assigneeLogins:i,authorLogin:a}=t||{},u=n||1;if(!o.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let l="searchCriteria.status=1";return i&&i.length&&(l+=`&searchCriteria.reviewerId=${i[0]}`),a&&(l+=`&searchCriteria.creatorId=${a}`),await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${r}&%24skip=${(u-1)*r}`,headers:P(this.config,e)})}async getPullRequestsForRepo(t,e={}){let n=t.page||1,o=await this.getPullRequestsForRepoBase(t,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(i=>he(t.repo.namespace,i))}}async getPullRequestsForRepos(t,e={}){if(!t.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:r}=t||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...t},e)).body.value.forEach(a=>{n.push(he(o.namespace,a))})}catch(i){if(i.statusCode!==404&&i.statusCode!==401)throw i}})),{data:n}}async getPullRequestsForProjectBase(t,e={},r=100){let{namespace:n,project:o,page:i,assigneeLogins:a,authorLogin:u}=t,l=i||1,p=new URL(`${e.baseUrl||q}/${encodeURIComponent(n)}/${encodeURIComponent(o)}/_apis/git/pullRequests`);return p.searchParams.set("searchCriteria.status","1"),p.searchParams.set("$top",r.toString()),p.searchParams.set("$skip",((l-1)*r).toString()),a&&a.length&&p.searchParams.set("searchCriteria.reviewerId",a[0]),u&&p.searchParams.set("searchCriteria.creatorId",u),await this.config.request({url:p.toString(),headers:P(this.config,e)})}async getPullRequestsForProject(t,e={}){let n=t.page||1,o=await this.getPullRequestsForProjectBase(t,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(i=>he(t.namespace,i))}}async getPullRequestsForProjects(t,e={}){let{projects:r}=t||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForProjectBase({...o,...t},e)).body.value.forEach(a=>{n.push(he(o.namespace,a))})}catch(i){if(i.statusCode!==404&&i.statusCode!==401)throw i}})),{data:n}}async getAzurePullRequestLastMergeStatus(t,e={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:r,project:n,name:o},pullRequestId:i}=t,a=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${i}?includeCommits=true?api-version=6.0`,headers:{...P(this.config,e)}});if(!a.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:a.body.mergeStatus}}async updatePullRequest(t,e,r){return await this.config.request({method:"PATCH",url:`${r.baseUrl||q}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}?api-version=6.0`,body:e,headers:{...P(this.config,r),"Content-Type":"application/json"}})}async closePullRequest(t,e={}){let{pullRequest:r}=t,n={status:"abandoned"};if(!(await this.updatePullRequest(r,JSON.stringify(n),e)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(t,e={}){var u;let{pullRequest:r,mergeStrategy:n}=t,o;switch(n){case"MERGE_COMMIT":{o="noFastForward";break}case"REBASE":{o="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{o="rebaseMerge";break}case"SQUASH":{o="squash";break}}let i={completionOptions:{mergeStrategy:o},lastMergeSourceCommit:{commitId:(u=r.headRef)==null?void 0:u.oid},status:"completed"};if(!(await this.updatePullRequest(r,JSON.stringify(i),e)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(t,e={}){let{pullRequest:r,label:n}=t;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o={name:n.name};if(!(await this.config.request({method:"POST",url:`${e.baseUrl||q}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/labels?api-version=6.0`,body:JSON.stringify(o),headers:{...P(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(t,e={}){let{pullRequest:r,label:n}=t;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');await this.config.request({method:"DELETE",url:`${e.baseUrl||q}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/labels/${encodeURIComponent(n.name)}?api-version=6.0`,headers:{...P(this.config,e)}})}async setPullRequestLabels(t,e={}){let{pullRequest:r,labels:n}=t;if(!r.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o=r.labels;if(!o)throw new Error('Azure DevOps requires "labels" for this function.');for(let i of n)o.find(a=>a.id===i.id)||await this.addPullRequestLabel({pullRequest:r,label:i},e);for(let i of o)n.find(a=>i.id===a.id)||await this.removePullRequestLabel({pullRequest:r,label:i},e)}async setPullRequestAsDraft(t,e={}){let{pullRequest:r,isDraft:n}=t,o={isDraft:n};if(!(await this.updatePullRequest(r,JSON.stringify(o),e)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(t,e={}){let{pullRequest:r,reviewer:n,isRequired:o}=t,i={id:n.id,isRequired:o};if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||q}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/reviewers/${n.id}?api-version=6.0`,body:JSON.stringify(i),headers:{...P(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(t,e={}){let{pullRequest:r,reviewer:n}=t;await this.config.request({method:"DELETE",url:`${e.baseUrl||q}/${encodeURIComponent(r.repository.owner.login)}/${encodeURIComponent(r.repository.project)}/_apis/git/repositories/${r.repository.name}/pullrequests/${r.id}/reviewers/${n.id}?api-version=6.0`,headers:{...P(this.config,e),Accept:"application/json"}})}async setPullRequestReviewers(t,e={}){let{pullRequest:r,reviewers:n}=t;for(let o of n)r.assignees.find(i=>i.id===o.id)||await this.addPullRequestReviewer({pullRequest:r,reviewer:o,isRequired:!0},e);for(let o of r.assignees)n.find(i=>o.id===i.id)||await this.removePullRequestReviewer({pullRequest:r,reviewer:o},e)}async getIssuesForAzureProject(t,e={}){let{page:r,assigneeLogins:n,authorLogin:o,mentionLogin:i,labelNames:a,statusByWorkItemIdByStatusId:u}=t||{},l=r||1,p=200,d=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&d.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),n&&n[0]&&d.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),i&&d.push("[System.Id] IN (@recentMentions)"),a&&a.forEach(R=>d.push(`[System.Tags] Contains '${R}'`));let c=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${d.join(" AND ")} order by [System.CreatedDate] desc`,g=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:c}),method:"POST",headers:{...P(this.config,e),"Content-Type":"application/json"}}),m=g.body.workItems.slice((l-1)*p,p*l).map(R=>R.id);if(m.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let h=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(t.namespace)}/${encodeURIComponent(t.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:m,$expand:"Links"}),method:"POST",headers:{...P(this.config,e),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:g.body.workItems.length>p*l,nextPage:l+1},data:h.body.value.map(R=>_r(t.namespace,t.project,R,u||{}))}}async updateIssue(t,e,r={}){return await this.config.request({method:"PATCH",url:`${r.baseUrl||q}/${encodeURIComponent(t.project.namespace)}/${encodeURIComponent(t.project.name)}/_apis/wit/workitems/${t.id}?api-version=6.0`,body:JSON.stringify(e),headers:{...P(this.config,r),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(t,e={}){var a;let{issue:r,status:n}=t,o=[{op:"add",path:"/fields/System.State",value:n.name}];if(!((a=(await this.updateIssue(r,o,e)).body.fields)!=null&&a["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(t,e={}){var a;let{issue:r,assignee:n}=t,o=[{op:"add",path:"/fields/System.AssignedTo",value:(n==null?void 0:n.name)??""}];if(!((a=(await this.updateIssue(r,o,e)).body.fields)!=null&&a["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(t,e={}){var u;let{issue:r,labels:n}=t,i=[{op:"replace",path:"/fields/System.Tags",value:n.map(l=>l.name).join(";")}];if(!((u=(await this.updateIssue(r,i,e)).body.fields)!=null&&u["System.Tags"]))throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(t,e={}){if(!t.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n}=t;return{data:(await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...P(this.config,e)}})).body.value}}async getLabelsForProject(t,e={}){let{namespace:r,project:n}=t;return{data:(await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...P(this.config,e)}})).body.value.map(i=>({color:null,description:null,id:i.id,name:i.name,url:i.url}))}}};var G=(s,t={})=>I(t.token||s.token,t.isPAT||s.isPAT);var k="https://api.bitbucket.org/2.0",Br={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},rr=s=>({id:s.uuid,name:s.display_name||s.nickname,username:s.nickname||s.display_name,email:null,avatarUrl:s.links.avatar.href,url:s.links.html.href}),tr=s=>{var t,e;return{id:s.uuid,namespace:s.workspace.slug,name:s.slug,webUrl:s.links.html.href,httpsUrl:((t=s.links.clone.find(r=>r.name==="https"))==null?void 0:t.href)??null,sshUrl:((e=s.links.clone.find(r=>r.name==="ssh"))==null?void 0:e.href)??null,defaultBranch:{name:s.mainbranch.name},permission:null}},at=s=>{let t=s.id;return{id:t.toString(),title:s.title,number:t,state:Br[s.state],isDraft:!1,commentCount:s.comment_count,upvoteCount:null,author:rr(s.author),createdDate:new Date(s.created_on),updatedDate:new Date(s.updated_on),closedDate:null,mergedDate:null,repository:{id:s.destination.repository.uuid,name:s.destination.repository.name,owner:{login:s.destination.repository.full_name.split("/")[0]},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:s.destination.branch.name,oid:s.destination.commit.hash},headRef:{name:s.source.branch.name,oid:s.source.commit.hash},url:s.links.html.href,assignees:null,reviews:null,reviewDecision:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",permissions:null}},se=class extends x{async refreshToken(t){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 ${t.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${t.refreshToken}`})).body}}async getCurrentUser(t={},e={}){let r=await this.config.request({url:`${k}/user`,headers:G(this.config,e)});return{data:rr(r.body)}}async getUserForCommit(t,e={}){var i;let n=(await this.config.request({url:`${k}/repositories/${t.repo.namespace}/${t.repo.name}/commit/${t.oid}`,headers:G(this.config,e)})).body.author,o=n.raw.match(/([^<]+)<(.+)>/);return{data:{name:o?o[1].trim():null,email:o?o[2]:null,avatarUrl:((i=n.user)==null?void 0:i.links.avatar.href)||null}}}async getRepo(t,e={}){let r=await this.config.request({url:`${k}/repositories/${t.namespace}/${t.name}`,headers:G(this.config,e)});return{data:tr(r.body)}}async getRepos(t,e={}){let r=[],n=[];return await Promise.all(t.map(async o=>{try{let i=await this.getRepo(o,e);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForCurrentUser(t,e={}){let r=new URL(`${k}/repositories`);r.searchParams.set("role","member"),r.searchParams.set("pagelen",S.toString()),t.cursor&&r.searchParams.set("after",t.cursor);let n=await this.config.request({url:r.toString(),headers:G(this.config,e)}),o=!!n.body.next,i=null;return n.body.next&&(i=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:i},data:n.body.values.map(tr)}}async getBranches(t,e={}){var i;let r=new URL(`${k}/repositories/${t.repo.namespace}/${t.repo.name}/refs/branches`);r.searchParams.set("page",((i=t.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen",S.toString());let n=await this.config.request({url:r.toString(),headers:G(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(a=>{let u=new Date(a.target.date);return{name:a.name,commit:{oid:a.target.hash,authoredDate:u,committedDate:u}}})}}async getTags(t,e={}){let r=new URL(`${k}/repositories/${t.repo.namespace}/${t.repo.name}/refs/tags`);r.searchParams.set("pagelen",S.toString()),t.cursor&&r.searchParams.set("page",t.cursor);let n=await this.config.request({url:r.toString(),headers:G(this.config,e)}),o=!!n.body.next,i=null;return n.body.next&&(i=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:i},data:n.body.values.map(a=>{let u=new Date(a.target.date);return{name:a.name,commit:{oid:a.target.hash,authoredDate:u,committedDate:u}}})}}async getPullRequestsForUser(t,e={}){var i;let r=new URL(`${k}/pullrequests/${t.userId}`);r.searchParams.set("page",((i=t.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen","50");let n=await this.config.request({url:r.toString(),headers:G(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(at)}}async getPullRequestsForRepoBase(t,e={}){var n;let r=new URL(`${k}/repositories/${encodeURI(t.repo.namespace)}/${encodeURI(t.repo.name)}/pullrequests?state=OPEN`);return r.searchParams.set("page",((n=t.page)==null?void 0:n.toString())||"1"),r.searchParams.set("pagelen","50"),await this.config.request({url:r.toString(),headers:G(this.config,e)})}async getPullRequestsForRepo(t,e={}){let r=[],n=await this.getPullRequestsForRepoBase(t,e);n.body.values.forEach(i=>{if(t.authorLogin&&i.author.uuid!==t.authorLogin)return null;r.push(at(i))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:r}}async getPullRequestsForRepos(t,e={}){let r=[];return await Promise.all(t.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...t},e)).body.values.forEach(i=>{if(t.authorLogin&&i.author.uuid!==t.authorLogin)return null;r.push(at(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async closePullRequest(t,e={}){let{pullRequest:r}=t;if(!(await this.config.request({method:"POST",url:`${k}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/decline`,headers:G(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(t,e={}){let{pullRequest:r,mergeStrategy:n}=t,o;switch(n){case"MERGE_COMMIT":{o="merge_commit";break}case"FAST_FORWARD":{o="fast_forward";break}case"SQUASH":{o="squash";break}}let i={merge_strategy:o,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${k}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/merge`,body:JSON.stringify(i),headers:{...G(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(t,e={}){let{pullRequest:r,reviewers:n}=t,o={reviewers:n.map(a=>{if(a.username)throw new Error('Bitbucket reviewer requires "username" for this function.');return{username:a.username}})};if(!(await this.config.request({method:"PUT",url:`${k}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}`,body:JSON.stringify(o),headers:{...G(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var ut=s=>({name:s.displayName,email:s.emailAddress,avatarUrl:s.avatarUrl??null,id:s.id.toString(),username:s.name,url:s.links.self[0].href}),ne=s=>{var u,l,p,d,c,g;let t={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},e={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},r=s.reviewers.map(m=>({reviewer:ut(m.user),state:e[m.status]})),n=((u=s.toRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:u.href)??null,o=((l=s.toRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:l.href)??null;o||(o=((p=s.toRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:p.href)??null);let i=((d=s.fromRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:d.href)??null,a=((c=s.fromRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:c.href)??null;return a||(a=((g=s.fromRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:g.href)??null),{id:s.id.toString(),number:s.id,title:s.title,url:s.links.self[0].href,state:t[s.state],isDraft:!1,createdDate:new Date(s.createdDate),updatedDate:new Date(s.updatedDate),closedDate:s.closedDate?new Date(s.closedDate):null,mergedDate:s.state=="MERGED"&&s.closedDate?new Date(s.closedDate):null,baseRef:{name:s.toRef.displayId,oid:s.toRef.latestCommit},headRef:{name:s.fromRef.displayId,oid:s.fromRef.latestCommit},commentCount:s.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:ut(s.author.user),assignees:null,reviews:r,reviewDecision:H(r),repository:{id:s.toRef.repository.id.toString(),name:s.toRef.repository.name,owner:{login:s.toRef.repository.project.key},remoteInfo:o&&n?{cloneUrlHTTPS:o,cloneUrlSSH:n}:null},headRepository:{id:s.fromRef.repository.id.toString(),name:s.fromRef.repository.name,owner:{login:s.fromRef.repository.project.key},remoteInfo:a&&i?{cloneUrlHTTPS:a,cloneUrlSSH:i}:null},headCommit:null,mergeableState:"UNKNOWN",permissions:null,version:s.version}},sr=s=>{var t,e,r;return{id:s.id.toString(),namespace:s.project.key,name:s.slug,webUrl:((t=s.links.self[0])==null?void 0:t.href)??null,httpsUrl:((e=s.links.clone.find(n=>n.name==="https"||n.name==="http"))==null?void 0:e.href)??null,sshUrl:((r=s.links.clone.find(n=>n.name==="ssh"))==null?void 0:r.href)??null,defaultBranch:null,permission:null}},oe=class extends B{getBaseUrl(t){let e=t.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(t){return I(t.token||this.config.token)}async getCurrentUser(t={},e={}){let r=await this.config.request({url:`${this.getBaseUrl(e)}/users?limit=2`,headers:this.getRequestHeaders(e)}),{headers:{"x-auserid":n,"x-ausername":o}}=r,i=n?parseInt(n,10):null,a=decodeURIComponent(o),l=(await this.config.request({url:`${this.getBaseUrl(e)}/users?filter=${o}&avatarSize=64`,headers:this.getRequestHeaders(e)})).body.values.find(({emailAddress:p,id:d,name:c,slug:g})=>i?i===d:a===c||a===p||a===g);if(!l)throw new Error("Could not find current Bitbucket Server user");return{data:ut(l)}}async getRepo(t,e={}){let r=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${t.namespace}/repos/${t.name}`,headers:this.getRequestHeaders(e)});return{data:sr(r.body)}}async getRepos(t,e={}){let r=[],n=[];return await Promise.all(t.map(async o=>{try{let i=await this.getRepo(o,e);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForCurrentUser(t,e={}){let r=t.page??0,n=await this.config.request({url:`${this.getBaseUrl(e)}/repos?start=${r}`,headers:this.getRequestHeaders(e)});return{pageInfo:{hasNextPage:!n.body.isLastPage,nextPage:n.body.nextPageStart},data:n.body.values.map(sr)}}async getPullRequestsForRepoBase(t,e={}){var n;let r=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(t.repo.namespace)}/repos/${encodeURI(t.repo.name)}/pull-requests?state=OPEN`);return r.searchParams.set("start",((n=t.page)==null?void 0:n.toString())||"0"),r.searchParams.set("limit","50"),await this.config.request({url:r.toString(),headers:this.getRequestHeaders(e)})}async getPullRequestsForRepo(t,e={}){let r=[],n=await this.getPullRequestsForRepoBase(t,e);n.body.values.forEach(i=>{if(t.authorLogin&&i.author.user.name!==t.authorLogin)return null;r.push(ne(i))});let o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:r}}async getPullRequestsForRepos(t,e={}){let r=[];return await Promise.all(t.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...t},e)).body.values.forEach(i=>{if(t.authorLogin&&i.author.user.name!==t.authorLogin)return null;r.push(ne(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async getPullRequestsForCurrentUser(t,e={}){var i;let r=new URL(`${this.getBaseUrl(e)}/dashboard/pull-requests`);r.searchParams.set("state","OPEN"),r.searchParams.set("start",((i=t.page)==null?void 0:i.toString())||"0"),r.searchParams.set("limit","50");let n=await this.config.request({url:r.toString(),headers:this.getRequestHeaders(e)}),o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:n.body.values.map(ne)}}async closePullRequest(t,e={}){let{pullRequest:r}=t;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/decline`,body:JSON.stringify({version:r.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(t,e={}){let{pullRequest:r,mergeStrategyId:n}=t;if(t.mergeStrategy)throw new Error('Bitbucket Server uses "mergeStrategyId" instead of "mergeStrategy".');if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/merge`,body:JSON.stringify({strategyId:n,version:r.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(t={}){let e=await this.config.request({url:`${this.getBaseUrl(t)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(t),"Content-Type":"application/json"}});return{data:{defaultStrategy:e.body.mergeConfig.defaultStrategy,strategies:e.body.mergeConfig.strategies}}}async setPullRequestReviewers(t,e={}){let{pullRequest:r,reviewers:n}=t;if(r.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');let o={reviewers:n.map(a=>{if(a.username)throw new Error('Bitbucket Server reviewer requires "username" for this function.');return{user:{name:a.username}}}),version:r.version};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}`,body:JSON.stringify(o),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var lr=require("js-base64");var Ie=(e=>(e.Open="OPEN",e.Closed="CLOSED",e))(Ie||{});var Qr={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0]},nr=15,or=100,U=s=>!!s,Re=(s,t)=>{let e=Qr[t];for(let r=0;r<3;r++){if(s[r]>e[r])return!0;if(s[r]<e[r])return!1}return!0},be="https://api.github.com",jr=`${be}/graphql`,we=`
|
|
2
2
|
description
|
|
3
3
|
dueOn
|
|
4
4
|
id
|
|
@@ -6,7 +6,7 @@ number
|
|
|
6
6
|
state
|
|
7
7
|
title
|
|
8
8
|
url
|
|
9
|
-
`,
|
|
9
|
+
`,Fr=`
|
|
10
10
|
... on CheckRun {
|
|
11
11
|
completedAt
|
|
12
12
|
conclusion
|
|
@@ -15,12 +15,12 @@ url
|
|
|
15
15
|
permalink
|
|
16
16
|
startedAt
|
|
17
17
|
}
|
|
18
|
-
`,
|
|
18
|
+
`,ye=/\/api\/v\d+$/,Pe=`
|
|
19
19
|
color
|
|
20
20
|
description
|
|
21
21
|
id
|
|
22
22
|
name
|
|
23
|
-
`,
|
|
23
|
+
`,ir=s=>{if(s.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.")},Mr=(s,t)=>{let e=t.baseUrl||s.baseUrl;return e?(e=e.replace(/\/$/,""),ir(e),ye.test(e)&&(e=e.replace(ye,"")),`${e}/api/graphql`):jr},lt=(s,t)=>{let e=t.baseUrl||s.baseUrl;return e?(e=e.replace(/\/$/,""),ir(e),ye.test(e)&&(e=e.replace(ye,"")),`${e}/api/v3`):be},y=(s,t,e)=>{let r=I(e.token||s.token);return r["X-Github-Next-Global-ID"]="1",r["Content-Type"]="application/json",r.Accept="application/vnd.github.merge-info-preview+json",s.request({url:Mr(s,e),method:"POST",headers:r,body:JSON.stringify(t)})},zr={user:!0,"user:email":!0,"read:user":!0},M=s=>s.some(t=>zr[t]),T=(s=!1,t=!1,e)=>`
|
|
24
24
|
__typename
|
|
25
25
|
${J(e,["graphQLId"],"id")}
|
|
26
26
|
${J(e,["id"],"databaseId")}
|
|
@@ -29,7 +29,7 @@ ${J(e,["name","username"],"login")}
|
|
|
29
29
|
${t?J(e,["email"],"email"):""}
|
|
30
30
|
${J(e,["avatarUrl"],`avatarUrl${s?"(size: $avatarSize)":""}`)}
|
|
31
31
|
${J(e,["url"],"url")}
|
|
32
|
-
`,
|
|
32
|
+
`,Wr=(s=!1)=>`
|
|
33
33
|
latestReviews(first: 100) {
|
|
34
34
|
nodes {
|
|
35
35
|
author {
|
|
@@ -40,14 +40,14 @@ latestReviews(first: 100) {
|
|
|
40
40
|
state
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
`,
|
|
43
|
+
`,ar=(s=!1)=>`
|
|
44
44
|
__typename
|
|
45
45
|
id
|
|
46
46
|
databaseId
|
|
47
47
|
login
|
|
48
48
|
avatarUrl${s?"(size: $avatarSize)":""}
|
|
49
49
|
url
|
|
50
|
-
`,
|
|
50
|
+
`,ve=(s,t=!1,e)=>`
|
|
51
51
|
id
|
|
52
52
|
databaseId
|
|
53
53
|
number
|
|
@@ -58,7 +58,7 @@ author {
|
|
|
58
58
|
${T(!1,t)}
|
|
59
59
|
}
|
|
60
60
|
... on Bot {
|
|
61
|
-
${
|
|
61
|
+
${ar(!1)}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
commits(last: 1) {
|
|
@@ -71,7 +71,7 @@ commits(last: 1) {
|
|
|
71
71
|
contexts(first: 100) {
|
|
72
72
|
totalCount
|
|
73
73
|
nodes {
|
|
74
|
-
${!e||
|
|
74
|
+
${!e||Re(e,"CHECK_RUN")?Fr:""}
|
|
75
75
|
... on StatusContext {
|
|
76
76
|
context
|
|
77
77
|
createdAt
|
|
@@ -138,7 +138,7 @@ assignees(first: 100) {
|
|
|
138
138
|
}
|
|
139
139
|
reviewRequests(first: 100) {
|
|
140
140
|
nodes {
|
|
141
|
-
${!e||
|
|
141
|
+
${!e||Re(e,"AS_CODE_OWNER")?"asCodeOwner":""}
|
|
142
142
|
requestedReviewer {
|
|
143
143
|
... on User {
|
|
144
144
|
${T(!1,t)}
|
|
@@ -146,22 +146,22 @@ reviewRequests(first: 100) {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
${!e||
|
|
149
|
+
${!e||Re(e,"LATEST_REVIEWS")?Wr(t):""}
|
|
150
150
|
additions
|
|
151
151
|
deletions
|
|
152
152
|
changedFiles
|
|
153
153
|
mergeable
|
|
154
154
|
mergeStateStatus
|
|
155
155
|
milestone {
|
|
156
|
-
${
|
|
156
|
+
${we}
|
|
157
157
|
}
|
|
158
158
|
labels(first: 100) {
|
|
159
159
|
nodes {
|
|
160
|
-
${
|
|
160
|
+
${Pe}
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
${!e||
|
|
164
|
-
`,
|
|
163
|
+
${!e||Re(e,"VIEWER_CAN_MERGE_AS_ADMIN")?"viewerCanMergeAsAdmin":""}
|
|
164
|
+
`,Hr=(s=!1)=>`
|
|
165
165
|
id
|
|
166
166
|
databaseId
|
|
167
167
|
title
|
|
@@ -170,7 +170,7 @@ author {
|
|
|
170
170
|
${T(!1,s)}
|
|
171
171
|
}
|
|
172
172
|
... on Bot {
|
|
173
|
-
${
|
|
173
|
+
${ar(!1)}
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
closedAt
|
|
@@ -199,14 +199,14 @@ assignees(first: 100) {
|
|
|
199
199
|
}
|
|
200
200
|
state
|
|
201
201
|
milestone {
|
|
202
|
-
${
|
|
202
|
+
${we}
|
|
203
203
|
}
|
|
204
204
|
labels(first: 100) {
|
|
205
205
|
nodes {
|
|
206
|
-
${
|
|
206
|
+
${Pe}
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
-
`,
|
|
209
|
+
`,Jr={"-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"},Vr=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),pt=s=>{let t=[];return(s.match(Vr)??[]).forEach(r=>{if(r.includes(":")&&r!="is:closed"){let n=r.split(":")[0];Jr[n]&&t.push(r)}}),t},dt=(s,t,e,r)=>{let n=s==="issue";return{query:`
|
|
210
210
|
query SearchIssuesOrPullRequests($query: String! $after: String) {
|
|
211
211
|
search(type:ISSUE query:$query first: ${r.maxPageSize} after:$after) {
|
|
212
212
|
pageInfo {
|
|
@@ -215,18 +215,18 @@ query SearchIssuesOrPullRequests($query: String! $after: String) {
|
|
|
215
215
|
}
|
|
216
216
|
nodes {
|
|
217
217
|
... on ${n?"Issue":"PullRequest"} {
|
|
218
|
-
${n?
|
|
218
|
+
${n?Hr(r.supportsEmail):ve(r.supportsDrafts??!1,r.supportsEmail,r.enterpriseVersion??null)}
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
|
-
}`,variables:{query:`is:${s} is:open ${r.includeFromArchivedRepos?"":"archived:false"} ${t}`,after:e}}},
|
|
222
|
+
}`,variables:{query:`is:${s} is:open ${r.includeFromArchivedRepos?"":"archived:false"} ${t}`,after:e}}},Kr="Field 'isDraft' doesn't exist on type 'PullRequest'",Ee=(s=[])=>s.some(t=>(t==null?void 0:t.message)===Kr),Xr=/@@ -(\d+)(?:,\d+ | )\+(\d+)(?:,\d+ | )@@(?:\\n)?/,Yr=`
|
|
223
223
|
\
|
|
224
|
-
+`,
|
|
224
|
+
+`,ur=(s,t,e,r)=>{let n=Xr.exec(s);if(!n||!n[0]||!n[1])return[];let o=parseInt(n[1],10),i=parseInt(n[2],10),a=s.replace(Yr,`
|
|
225
225
|
+`).split(`
|
|
226
|
-
`).slice(1),u=o-1,l=i-1,p=a.map(
|
|
227
|
-
`;break}case"+":{m="ADDED",l+=1,h=`${
|
|
228
|
-
`;break}default:m="UNMODIFIED",l+=1,u+=1,h=`${
|
|
229
|
-
`}return{line:h,oldLineNumber:m!=="ADDED"?u:null,newLineNumber:m!=="DELETED"?l:null,type:m}}),d=e,
|
|
226
|
+
`).slice(1),u=o-1,l=i-1,p=a.map(g=>{let m,h;switch(g[0]){case"-":{m="DELETED",u+=1,h=`${g.slice(1)}
|
|
227
|
+
`;break}case"+":{m="ADDED",l+=1,h=`${g.slice(1)}
|
|
228
|
+
`;break}default:m="UNMODIFIED",l+=1,u+=1,h=`${g}
|
|
229
|
+
`}return{line:h,oldLineNumber:m!=="ADDED"?u:null,newLineNumber:m!=="DELETED"?l:null,type:m}}),d=e,c=t;if(d!==null&&c!==null&&r!==null&&d<c){let g=0,m=p.length,h=r==="LEFT"?"oldLineNumber":"newLineNumber";for(let R=0;R<p.length;R++){let f=p[R][h];f===d?g=R:f===c&&(m=R)}p=p.slice(g,m+1)}return p};var ct=`
|
|
230
230
|
id
|
|
231
231
|
databaseId
|
|
232
232
|
owner {
|
|
@@ -239,13 +239,13 @@ defaultBranchRef {
|
|
|
239
239
|
name
|
|
240
240
|
}
|
|
241
241
|
viewerPermission
|
|
242
|
-
`,
|
|
242
|
+
`,ht={__typename:"User",id:"U_kgDNJ5k",databaseId:10137,name:"Deleted user",login:"ghost",email:"",avatarUrl:"https://avatars.githubusercontent.com/u/10137?v=4",url:"https://github.com/ghost"},Zr={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},es={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},ts={BEHIND:"BEHIND",BLOCKED:"BLOCKED",UNKNOWN:"UNKNOWN_AND_BLOCKED",UNSTABLE:"UNSTABLE",CLEAN:null,DIRTY:null,DRAFT:null,HAS_HOOKS:null},rs={OPEN:"OPEN",CLOSED:"CLOSED"},ss=["ADMIN","MAINTAIN","TRIAGE","WRITE"],ft=s=>({color:`#${s.color}`,description:s.description,graphQLId:s.id,id:null,name:s.name}),gt=s=>({id:s.databaseId.toString(),graphQLId:s.id,namespace:s.owner.login,name:s.name,webUrl:s.url,httpsUrl:s.url.endsWith(".git")?s.url:`${s.url}.git`,sshUrl:s.sshUrl,defaultBranch:s.defaultBranchRef,permission:s.viewerPermission}),ns={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},os={id:!0,graphQLId:!0,name:!0,username:!0,email:!0,avatarUrl:!0,url:!0},N=(s,t=os)=>{let e={};return t.id&&(e.id=s.databaseId.toString()),t.graphQLId&&(e.graphQLId=s.id),t.name&&(e.name=s.name??s.login),t.username&&(e.username=s.login),t.email&&(e.email=s.email??null),t.avatarUrl&&(e.avatarUrl=s.avatarUrl),t.url&&(e.url=s.url),e},is=(s,t)=>{let e={IN_PROGRESS:"RUNNING",PENDING:"PENDING",QUEUED:"PENDING",REQUESTED:"PENDING",WAITING:"PENDING"};return s!=="COMPLETED"?e[s]:{ACTION_REQUIRED:"ACTION_REQUIRED",CANCELLED:"CANCELLED",FAILURE:"FAILED",NEUTRAL:null,SKIPPED:"SKIPPED",STALE:"FAILED",STARTUP_FAILURE:"FAILED",SUCCESS:"SUCCESS",TIMED_OUT:"ERROR"}[t]},as=s=>({ERROR:"ERROR",EXPECTED:"PENDING",FAILURE:"FAILED",PENDING:"PENDING",SUCCESS:"SUCCESS"})[s],mt=s=>{var i,a,u,l,p,d,c,g,m,h,R,w;let t=null;s.author?t=(s.author.__typename==="Bot",s.author):t=ht;let e=(((i=s.reviewRequests)==null?void 0:i.nodes)||[]).filter(U).filter(f=>!f.asCodeOwner),r=(a=s.headRepository)==null?void 0:a.url;r&&!r.endsWith(".git")&&(r=`${r}.git`);let n=(u=s.repository)==null?void 0:u.url;n&&!n.endsWith(".git")&&(n=`${n}.git`);let o=e.filter(f=>f.requestedReviewer&&"__typename"in f.requestedReviewer).map(f=>({reviewer:N(f.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((((l=s.latestReviews)==null?void 0:l.nodes)||[]).filter(U).map(f=>{let v=ht;return f.author&&Object.keys(f.author).length>0&&(v=f.author),{reviewer:N(v),state:Zr[f.state]}}));return{id:s.databaseId.toString(),graphQLId:s.id,title:s.title,number:s.number,state:ns[s.state],commentCount:s.comments.totalCount,upvoteCount:s.reactions.totalCount,author:t?N(t):null,createdDate:new Date(s.createdAt),isDraft:s.isDraft,repository:{id:s.repository.databaseId,graphQLId:s.repository.id,name:s.repository.name,owner:{login:s.repository.owner.login},remoteInfo:{cloneUrlHTTPS:n,cloneUrlSSH:s.repository.sshUrl}},headRepository:s.headRepository?{id:s.headRepository.databaseId,graphQLId:s.headRepository.id,name:s.headRepository.name,owner:{login:s.headRepository.owner.login},remoteInfo:{cloneUrlHTTPS:r,cloneUrlSSH:s.headRepository.sshUrl}}:null,headCommit:{buildStatuses:((g=(c=(d=(p=s.commits.nodes)==null?void 0:p.filter(U)[0])==null?void 0:d.commit.statusCheckRollup)==null?void 0:c.contexts.nodes)==null?void 0:g.filter(U).map(f=>"context"in f?{completedAt:null,description:f.description,name:f.context,state:as(f.state),startedAt:new Date(f.createdAt),stage:null,url:f.targetUrl}:{completedAt:f.completedAt?new Date(f.completedAt):null,description:null,name:f.name,state:is(f.status,f.conclusion),startedAt:f.startedAt?new Date(f.startedAt):null,stage:null,url:f.permalink}))??[]},headRef:s.headRef?{name:s.headRef.name,oid:((m=s.headRef.target)==null?void 0:m.oid)??null}:null,baseRef:s.baseRef?{name:s.baseRef.name,oid:((h=s.baseRef.target)==null?void 0:h.oid)??null}:null,url:s.url,updatedDate:new Date(s.updatedAt),closedDate:s.closedAt?new Date(s.closedAt):null,mergedDate:s.mergedAt?new Date(s.mergedAt):null,assignees:s.assignees.nodes?s.assignees.nodes.filter(U).map(f=>N(f)):null,reviews:o,reviewDecision:H(o),additions:s.additions,deletions:s.deletions,fileCount:s.changedFiles,commitCount:s.commits.totalCount,mergeableState:ts[s.mergeStateStatus]??es[s.mergeable],milestone:s.milestone?It(s.milestone):null,labels:((w=(R=s.labels)==null?void 0:R.nodes)==null?void 0:w.filter(U).map(ft))??[],permissions:{canMerge:ss.includes(s.repository.viewerPermission),canMergeAndBypassProtections:s.viewerCanMergeAsAdmin??!1}}},us=s=>{var h,R;let{comments:t,isOutdated:e,isResolved:r,originalLine:n,originalStartLine:o,startDiffSide:i}=s,a=(h=t.nodes)==null?void 0:h[0];if(!a)return null;let{author:u,body:l,databaseId:p,id:d,path:c,publishedAt:g,url:m}=a;return{author:u?{avatarUrl:u.avatarUrl,email:null,name:u.login}:null,body:l,createdAt:g?new Date(g):null,diffLines:ur(a.diffHunk,n,o,i),id:p,isOutdated:e,isResolved:r,graphQLId:d,filename:c,replies:((R=t.nodes)==null?void 0:R.filter(U).slice(1).map(ls))??[],url:m}},ls=s=>({author:s.author?{avatarUrl:s.author.avatarUrl,email:null,name:s.author.login}:null,body:s.body,createdAt:s.publishedAt?new Date(s.publishedAt):null,graphQLId:s.id,id:s.databaseId,url:s.url}),ps=s=>{var e,r,n;let t=null;return s.author?t=(s.author.__typename==="Bot",s.author):t=ht,{id:s.databaseId.toString(),graphQLId:s.id,number:s.number,title:s.title,author:N(t),commentCount:s.comments.totalCount,closedDate:s.closedAt?new Date(s.closedAt):null,createdDate:new Date(s.createdAt),description:null,state:{name:rs[s.state],color:null},type:null,repository:{id:s.repository.databaseId,graphQLId:s.repository.id,name:s.repository.name,owner:{login:s.repository.owner.login}},url:s.url,updatedDate:new Date(s.updatedAt),assignees:((e=s.assignees.nodes)==null?void 0:e.filter(U).map(o=>N(o)))??[],upvoteCount:s.reactions.totalCount,milestone:s.milestone?It(s.milestone):null,labels:((n=(r=s.labels)==null?void 0:r.nodes)==null?void 0:n.filter(U).map(ft))??[]}},It=s=>({id:s.number.toString(),graphQLId:s.id.toString(),number:s.number,title:s.title,description:s.description,isOpen:s.state=="OPEN",url:s.url,startDate:null,dueDate:s.dueOn?new Date(s.dueOn):null}),ie=class extends B{constructor(){super(...arguments);this._scopesCache={};this._enterpriseVersionsCache={}}async getScopes(e){let r=e.token||this.config.token;if(!r)return[];let n=this._scopesCache[r];if(!n){let i=(await y(this.config,{query:"query { rateLimit(dryRun: true) { __typename } }"},e)).headers["x-oauth-scopes"];n=i?i.split(", "):[],this._scopesCache[r]=n}return n}async getEnterpriseVersion(e){let r=e.baseUrl||this.config.baseUrl;if(!r)return null;let n=this._enterpriseVersionsCache[r];if(!n){let o=await this.config.request({url:`${lt(this.config,e)}/meta`,headers:I(e.token||this.config.token)});if(!o.body.installed_version)return null;n=o.body.installed_version.split(".").slice(0,3).map(i=>parseInt(i,10)),this._enterpriseVersionsCache[r]=n}return n}getEnterpriseAvatarUrlIfNeeded(e,r,n){let o=n.baseUrl||this.config.baseUrl;return!o||o.startsWith(be)?e:r?`https://avatars.githubusercontent.com/u/e?email=${encodeURIComponent(r)}`:""}async getCurrentUser(e={},r={}){var u;if(e.fields&&!e.fields.length)throw new Error('"fields" must contain at least one field or be omitted');let n=Kt(e.fields),o=await this.getScopes(r),a=(u=(await y(this.config,{query:`
|
|
243
243
|
query getCurrentUser {
|
|
244
244
|
viewer {
|
|
245
245
|
${T(!1,M(o),n)}
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
|
-
`},r)).body.data)==null?void 0:u.viewer;if(!a)throw new Error("Current user not found.");return{data:N(a,n)}}async getAccountsForRepo(e,r={}){var l,p,d,g,
|
|
248
|
+
`},r)).body.data)==null?void 0:u.viewer;if(!a)throw new Error("Current user not found.");return{data:N(a,n)}}async getAccountsForRepo(e,r={}){var l,p,d,c,g,m;let n=await this.getScopes(r),{repo:{namespace:o,name:i},cursor:a}=e,u=await y(this.config,{query:`
|
|
249
249
|
query getAccountsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
|
|
250
250
|
repository(owner: $owner, name: $name) {
|
|
251
251
|
assignableUsers(first: $first, after: $cursor) {
|
|
@@ -259,7 +259,7 @@ query getAccountsForRepo($owner: String!, $name: String! $cursor: String, $first
|
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
|
-
`,variables:{owner:o,name:i,cursor:a,first:S}},r);if(!u.body.data)throw new Error(((l=u.body.errors)==null?void 0:l[0].message)||u.statusText||"Unknown error");return{pageInfo:((d=(p=u.body.data.repository)==null?void 0:p.assignableUsers)==null?void 0:d.pageInfo)??{endCursor:null,hasNextPage:!1},data:((m=(
|
|
262
|
+
`,variables:{owner:o,name:i,cursor:a,first:S}},r);if(!u.body.data)throw new Error(((l=u.body.errors)==null?void 0:l[0].message)||u.statusText||"Unknown error");return{pageInfo:((d=(p=u.body.data.repository)==null?void 0:p.assignableUsers)==null?void 0:d.pageInfo)??{endCursor:null,hasNextPage:!1},data:((m=(g=(c=u.body.data.repository)==null?void 0:c.assignableUsers)==null?void 0:g.nodes)==null?void 0:m.map(h=>N(h)))??[]}}async getUserForCommit(e,r={}){var a,u;let o=(a=(await y(this.config,{query:`
|
|
263
263
|
query getUserForCommit(
|
|
264
264
|
$owner: String!
|
|
265
265
|
$name: String!
|
|
@@ -305,7 +305,7 @@ mutation createCommitOnBranch(
|
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
|
-
`,variables:{branchName:u.name,expectedHeadOid:u.oid,fileChanges:{additions:Object.entries(i).map(([d,
|
|
308
|
+
`,variables:{branchName:u.name,expectedHeadOid:u.oid,fileChanges:{additions:Object.entries(i).map(([d,c])=>({contents:lr.Base64.encode(c),path:d})),deletions:o.map(d=>({path:d}))},message:{body:n.description,headline:n.summary},repositoryNameWithOwner:`${a.namespace}/${a.name}`}},r);if((p=l.body.errors)!=null&&p[0])throw new Error(l.body.errors[0].message);if(!l.body.data)throw new Error("Could not create commit");return{data:{name:l.body.data.createCommitOnBranch.ref.name,commit:{authoredDate:new Date(l.body.data.createCommitOnBranch.commit.authoredDate),committedDate:new Date(l.body.data.createCommitOnBranch.commit.committedDate),oid:l.body.data.createCommitOnBranch.commit.oid}}}}async getAccountForEmail(e,r={}){var a,u,l;let n=await this.getScopes(r),i=(l=(u=(a=(await y(this.config,{query:`
|
|
309
309
|
query getAccountForEmail($query: String! $avatarSize: Int) {
|
|
310
310
|
search(query: $query, type: USER, first: 1) {
|
|
311
311
|
nodes {
|
|
@@ -359,19 +359,19 @@ query getOrgMember($cursor: String, $first: Int!, $login: String!) {
|
|
|
359
359
|
`,variables:{cursor:e.cursor,first:S,login:e.org}},r);if(!n.body.data)throw new Error(((i=n.body.errors)==null?void 0:i[0].message)||n.statusText||"Unknown error");if(!((u=(a=n.body.data)==null?void 0:a.viewer.organization)!=null&&u.membersWithRole))throw new Error("Could not read the members of the organization");let o=n.body.data.viewer.organization.membersWithRole.nodes||[];return{pageInfo:n.body.data.viewer.organization.membersWithRole.pageInfo,data:o.map(l=>N({...l,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(l.avatarUrl,l.email,r)}))}}async getRepo(e,r={}){var o;let n=await y(this.config,{query:`
|
|
360
360
|
query getRepo($owner: String!, $name: String!) {
|
|
361
361
|
repository(owner: $owner, name: $name) {
|
|
362
|
-
${
|
|
362
|
+
${ct}
|
|
363
363
|
}
|
|
364
364
|
}
|
|
365
|
-
`,variables:{owner:e.namespace,name:e.name}},r);if(!((o=n.body.data)!=null&&o.repository))throw new Error(`Repository ${e.namespace}/${e.name} not found`);return{data:
|
|
365
|
+
`,variables:{owner:e.namespace,name:e.name}},r);if(!((o=n.body.data)!=null&&o.repository))throw new Error(`Repository ${e.namespace}/${e.name} not found`);return{data:gt(n.body.data.repository)}}async getRepos(e,r={}){let n=e.map(({namespace:u,name:l},p)=>`
|
|
366
366
|
getRepo_${p}: repository(owner: "${u}", name: "${l}") {
|
|
367
|
-
${
|
|
367
|
+
${ct}
|
|
368
368
|
}
|
|
369
369
|
`).join(`
|
|
370
370
|
`),o=await y(this.config,{query:`
|
|
371
371
|
query batchGetRepos {
|
|
372
372
|
${n}
|
|
373
373
|
}
|
|
374
|
-
`},r);if(!o.body.data)throw new Error(o.statusText||"Unknown error");let i=[],a=[];return e.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?i.push(
|
|
374
|
+
`},r);if(!o.body.data)throw new Error(o.statusText||"Unknown error");let i=[],a=[];return e.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?i.push(gt(p)):a.push({input:u})}),{data:i,errors:a}}async getReposForUsernames(e,r={}){var i;if(!e.usernames.length)return{pageInfo:{endCursor:null,hasNextPage:!1},data:[]};let n=await y(this.config,{query:`
|
|
375
375
|
query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
|
|
376
376
|
search(query: $query, type: REPOSITORY, first: $first, after: $cursor) {
|
|
377
377
|
pageInfo {
|
|
@@ -380,12 +380,12 @@ query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
|
|
|
380
380
|
}
|
|
381
381
|
nodes {
|
|
382
382
|
... on Repository {
|
|
383
|
-
${
|
|
383
|
+
${ct}
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
386
|
}
|
|
387
387
|
}
|
|
388
|
-
`,variables:{query:`fork:true ${e.usernames.map(a=>`user:${a}`).join(" ")}`,cursor:e.cursor,first:S}},r);if(!n.body.data)throw new Error(((i=n.body.errors)==null?void 0:i[0].message)||n.statusText||"Unknown error");let o=n.body.data.search.nodes||[];return{pageInfo:n.body.data.search.pageInfo,data:o.map(
|
|
388
|
+
`,variables:{query:`fork:true ${e.usernames.map(a=>`user:${a}`).join(" ")}`,cursor:e.cursor,first:S}},r);if(!n.body.data)throw new Error(((i=n.body.errors)==null?void 0:i[0].message)||n.statusText||"Unknown error");let o=n.body.data.search.nodes||[];return{pageInfo:n.body.data.search.pageInfo,data:o.map(gt)}}async getReposForOwners(e,r={}){return this.getReposForUsernames({usernames:e.owners.filter(n=>n.username).map(n=>n.username),cursor:e.cursor},r)}async getRefs(e,r,n={}){var u;let i=(u=(await y(this.config,{query:`
|
|
389
389
|
query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: String, $first: Int!) {
|
|
390
390
|
repository(owner: $owner, name: $name) {
|
|
391
391
|
refs(refPrefix: $refPrefix first: $first after: $cursor) {
|
|
@@ -445,7 +445,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
445
445
|
}
|
|
446
446
|
}
|
|
447
447
|
}
|
|
448
|
-
`,variables:{owner:e.repo.namespace,name:e.repo.name,ref:e.ref,path:e.path}},r)).body.data)==null?void 0:a.repository;if(!o)throw new Error("Repository not found.");let i=o.object;if(!i||!("blame"in i))throw new Error("Ref not found.");if(i.blame.ranges.length===0)throw new Error("File not found.");return{data:{ranges:i.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 getFileContents(e,r={}){let n=await this.config.request({url:`${
|
|
448
|
+
`,variables:{owner:e.repo.namespace,name:e.repo.name,ref:e.ref,path:e.path}},r)).body.data)==null?void 0:a.repository;if(!o)throw new Error("Repository not found.");let i=o.object;if(!i||!("blame"in i))throw new Error("Ref not found.");if(i.blame.ranges.length===0)throw new Error("File not found.");return{data:{ranges:i.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 getFileContents(e,r={}){let n=await this.config.request({url:`${lt(this.config,r)}/repos/${e.repo.namespace}/${e.repo.name}/contents/${encodeURIComponent(e.path)}?ref=${e.ref}`,headers:{...I(r.token||this.config.token),Accept:"application/vnd.github.raw+json"}});if(n.headers["content-type"].startsWith("application/json"))throw new Error(`GitHub: got directory when fetching "${e.path}", getFileContents does not support fetching directories`);if(!n.headers["content-type"].startsWith("application/vnd.github.raw+json"))throw new Error(`GitHub: unsupported content type "${n.headers["content-type"]}" when fetching "${e.path}"`);return{data:new Blob([n.body])}}async searchPullRequests(e,r={}){var p,d;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),i=M(o),a=c=>{let g=c&&typeof e.isDraft=="boolean"?`${e.query} draft:${e.isDraft}`:e.query;return dt("pr",g,e.cursor,{maxPageSize:e.maxPageSize??nr,supportsEmail:i,supportsDrafts:c,enterpriseVersion:n,includeFromArchivedRepos:e.includeFromArchivedRepos})},u=await y(this.config,a(!0),r);u.body.errors&&Ee(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await y(this.config,a(!1),r));let{data:l}=u.body;if(!l)throw new Error(((p=u.body.errors)==null?void 0:p[0].message)||u.statusText||"Unknown error");return{pageInfo:{hasNextPage:l.search.pageInfo.hasNextPage,endCursor:l.search.pageInfo.endCursor},data:((d=l.search.nodes)==null?void 0:d.filter(U).map(mt))||[]}}async searchIssues(e,r={}){var u,l;let n=await this.getScopes(r),o=M(n),i=await y(this.config,dt("issue",e.query,e.cursor,{supportsEmail:o,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize??or}),r),{data:a}=i.body;if(!a)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:{hasNextPage:a.search.pageInfo.hasNextPage,endCursor:a.search.pageInfo.endCursor},data:((l=a.search.nodes)==null?void 0:l.map(ps))||[]}}async getPullRequestsAssociatedWithUser(e,r={}){let n=[`involves:${e.username}`];return e.labelNames&&e.labelNames.forEach(o=>{n.push(`label:"${o}"`)}),this.searchPullRequests({query:n.join(" "),cursor:e.cursor,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},r)}async getPullRequestsForRepos(e,r={}){let{assigneeLogins:n,updatedBefore:o,authorLogin:i,repos:a,reviewRequestedLogin:u,startQuery:l,mentionLogin:p,labelNames:d,maxPageSize:c}=e,g=pt(l||"");return a.forEach(m=>{g.push(`repo:${m.namespace}/${m.name}`)}),n&&n.forEach(m=>{g.push(`assignee:${m}`)}),o&&g.push(`updated:<${o}`),i&&g.push(`author:${i}`),u&&g.push(`review-requested:${u}`),p&&g.push(`mentions:${p}`),d&&d.forEach(m=>{g.push(`label:"${m}"`)}),this.searchPullRequests({query:`sort:updated ${g.join(" ")}`,isDraft:e.isDraft,cursor:e.cursor,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:c},r)}async getPullRequestForRepo(e,r={}){var d,c;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),i=M(o),a=g=>({query:`query getPullRequest(
|
|
449
449
|
$owner: String!
|
|
450
450
|
$name: String!
|
|
451
451
|
$number: Int!
|
|
@@ -455,24 +455,24 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
455
455
|
name: $name
|
|
456
456
|
) {
|
|
457
457
|
pullRequest(number: $number) {
|
|
458
|
-
${
|
|
458
|
+
${ve(g,i,n)}
|
|
459
459
|
}
|
|
460
460
|
}
|
|
461
|
-
}`,variables:{owner:e.repo.namespace,name:e.repo.name,number:e.number}}),u=await y(this.config,a(!0),r);u.body.errors&&
|
|
461
|
+
}`,variables:{owner:e.repo.namespace,name:e.repo.name,number:e.number}}),u=await y(this.config,a(!0),r);u.body.errors&&Ee(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await y(this.config,a(!1),r));let{data:l}=u.body;if(!l)throw new Error(((d=u.body.errors)==null?void 0:d[0].message)||u.statusText||"Unknown error");let p=(c=u.body.data)==null?void 0:c.repository.pullRequest;return{data:p?mt(p):null}}async getPullRequestByGraphQLId(e,r={}){var d,c;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),i=M(o),a=g=>({query:`query getPullRequest(
|
|
462
462
|
$graphQLId: ID!
|
|
463
463
|
) {
|
|
464
464
|
node(id: $graphQLId) {
|
|
465
465
|
... on PullRequest {
|
|
466
|
-
${
|
|
466
|
+
${ve(g,i,n)}
|
|
467
467
|
}
|
|
468
468
|
}
|
|
469
|
-
}`,variables:{graphQLId:e.graphQLId}}),u=await y(this.config,a(!0),r);u.body.errors&&
|
|
469
|
+
}`,variables:{graphQLId:e.graphQLId}}),u=await y(this.config,a(!0),r);u.body.errors&&Ee(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await y(this.config,a(!1),r));let{data:l}=u.body;if(!l)throw new Error(((d=u.body.errors)==null?void 0:d[0].message)||u.statusText||"Unknown error");let p=(c=u.body.data)==null?void 0:c.node;return{data:p?mt(p):null}}async closePullRequest(e,r={}){var a,u,l;let{pullRequest:{graphQLId:n}}=e;if(!n)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation ClosePullRequest($pullRequestGraphQLId: ID!) {
|
|
470
470
|
closePullRequest(input: { pullRequestId: $pullRequestGraphQLId }) {
|
|
471
471
|
pullRequest {
|
|
472
472
|
id
|
|
473
473
|
}
|
|
474
474
|
}
|
|
475
|
-
}`;if(!((l=(u=(a=(await y(this.config,{query:`${o}`,variables:{pullRequestGraphQLId:n}},r)).body.data)==null?void 0:a.closePullRequest)==null?void 0:u.pullRequest)!=null&&l.id))throw new Error("Could not close pull request")}async mergePullRequest(e,r={}){var l,p,d,
|
|
475
|
+
}`;if(!((l=(u=(a=(await y(this.config,{query:`${o}`,variables:{pullRequestGraphQLId:n}},r)).body.data)==null?void 0:a.closePullRequest)==null?void 0:u.pullRequest)!=null&&l.id))throw new Error("Could not close pull request")}async mergePullRequest(e,r={}){var l,p,d,c;let{pullRequest:n,mergeStrategy:o}=e;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');if(!((l=n.headRef)!=null&&l.oid))throw new Error('GitHub requires "headRef.oid" for this function.');let i;switch(o){case"MERGE_COMMIT":{i="MERGE";break}case"REBASE":{i="REBASE";break}case"SQUASH":{i="SQUASH";break}}let a=`mutation MergePullRequest(
|
|
476
476
|
$pullRequestGraphQLId: ID!,
|
|
477
477
|
$expectedSourceSha: GitObjectID!,
|
|
478
478
|
$mergeStrategy: PullRequestMergeMethod,
|
|
@@ -486,7 +486,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
486
486
|
id
|
|
487
487
|
}
|
|
488
488
|
}
|
|
489
|
-
}`;if(!((
|
|
489
|
+
}`;if(!((c=(d=(p=(await y(this.config,{query:`${a}`,variables:{pullRequestGraphQLId:n.graphQLId,expectedSourceSha:n.headRef.oid,mergeStrategy:i}},r)).body.data)==null?void 0:p.mergePullRequest)==null?void 0:d.pullRequest)!=null&&c.id))throw new Error("Could not merge pull request")}async setPullRequestMilestone(e,r={}){var u,l,p;let{pullRequest:n,milestone:o}=e;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation SetPullRequestMilestone($pullRequestGraphQLId: ID!, $milestoneGraphQLId: ID) {
|
|
490
490
|
updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, milestoneId: $milestoneGraphQLId }) {
|
|
491
491
|
pullRequest {
|
|
492
492
|
id
|
|
@@ -504,25 +504,25 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
504
504
|
id
|
|
505
505
|
}
|
|
506
506
|
}
|
|
507
|
-
}`;if(!((u=(a=(i=(await y(this.config,{query:n,variables:{pullRequestGraphQLId:e}},r)).body.data)==null?void 0:i.convertPullRequestToDraft)==null?void 0:a.pullRequest)!=null&&u.id))throw new Error("Could not convert pull request to draft")}async setPullRequestAsDraft(e,r={}){let{pullRequest:{graphQLId:n},isDraft:o}=e;if(!n)throw new Error('GitHub requires "graphQLId" for this function.');if(o){await this.convertPullRequestToDraft(n,r);return}await this.markPullRequestReadyForReview(n,r)}async setPullRequestReviewers(e,r={}){var d,g
|
|
507
|
+
}`;if(!((u=(a=(i=(await y(this.config,{query:n,variables:{pullRequestGraphQLId:e}},r)).body.data)==null?void 0:i.convertPullRequestToDraft)==null?void 0:a.pullRequest)!=null&&u.id))throw new Error("Could not convert pull request to draft")}async setPullRequestAsDraft(e,r={}){let{pullRequest:{graphQLId:n},isDraft:o}=e;if(!n)throw new Error('GitHub requires "graphQLId" for this function.');if(o){await this.convertPullRequestToDraft(n,r);return}await this.markPullRequestReadyForReview(n,r)}async setPullRequestReviewers(e,r={}){var d,c,g;let{pullRequest:{reviews:n,graphQLId:o},reviewers:i}=e;if(!n)throw new Error('GitHub requires "reviews" for this function');if(!o)throw new Error('GitHub requires "graphQLId" for this function.');let a=n.filter(m=>m.state!=="REVIEW_REQUESTED").map(m=>{if(!m.reviewer.graphQLId)throw new Error('GitHub requires reviewer "graphQLId" for this function.');return m.reviewer.graphQLId}),u=i.map(m=>{if(!m.graphQLId)throw new Error('GitHub requires reviewer "graphQLId" for this function.');return m.graphQLId}).filter(m=>a.indexOf(m)===-1),l=`mutation SetPullRequestReviewers($pullRequestGraphQLId: ID!, $reviewerGraphQLIds: [ID!]!) {
|
|
508
508
|
requestReviews(input: { pullRequestId: $pullRequestGraphQLId, userIds: $reviewerGraphQLIds }) {
|
|
509
509
|
pullRequest {
|
|
510
510
|
id
|
|
511
511
|
}
|
|
512
512
|
}
|
|
513
|
-
}`;if(!((
|
|
513
|
+
}`;if(!((g=(c=(d=(await y(this.config,{query:l,variables:{pullRequestGraphQLId:o,reviewerGraphQLIds:u}},r)).body.data)==null?void 0:d.requestReviews)==null?void 0:c.pullRequest)!=null&&g.id))throw new Error("Could not set pull request reviewers")}async reRequestPullRequestReviews(e,r={}){var p,d,c;let{pullRequest:{reviews:n,graphQLId:o},reviewers:i}=e;if(!o)throw new Error('GitHub requires "graphQLId" for this function.');if(!n)throw new Error('GitHub requires "reviews" for this function.');let a=[];for(let g of i){if(!g.graphQLId)throw new Error('GitHub requires reviwer "graphQLId" for this function.');if(!n.find(m=>m.reviewer.graphQLId===g.graphQLId))throw new Error("Can only re-request review from existing reviewer.");a.push(g.graphQLId)}let u=`mutation SetPullRequestReviewers($pullRequestGraphQLId: ID!, $reviewerGraphQLIds: [ID!]!) {
|
|
514
514
|
requestReviews(input: { pullRequestId: $pullRequestGraphQLId, userIds: $reviewerGraphQLIds, union: true }) {
|
|
515
515
|
pullRequest {
|
|
516
516
|
id
|
|
517
517
|
}
|
|
518
518
|
}
|
|
519
|
-
}`;if(!((
|
|
519
|
+
}`;if(!((c=(d=(p=(await y(this.config,{query:u,variables:{pullRequestGraphQLId:o,reviewerGraphQLIds:a}},r)).body.data)==null?void 0:p.requestReviews)==null?void 0:d.pullRequest)!=null&&c.id))throw new Error("Could not re-request pull request reviews")}async setPullRequestAssignees(e,r={}){var l,p,d;let{pullRequest:n,assignees:o}=e;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=o.map(c=>{if(!c.graphQLId)throw new Error('GitHub requires assignee "graphQLId" for this function.');return c.graphQLId}),a=`mutation SetPullRequestAssignees($pullRequestGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
|
|
520
520
|
updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, assigneeIds: $assigneeGraphQLIds }) {
|
|
521
521
|
pullRequest {
|
|
522
522
|
id
|
|
523
523
|
}
|
|
524
524
|
}
|
|
525
|
-
}`;if(!((d=(p=(l=(await y(this.config,{query:a,variables:{pullRequestGraphQLId:n.graphQLId,assigneeGraphQLIds:i}},r)).body.data)==null?void 0:l.updatePullRequest)==null?void 0:p.pullRequest)!=null&&d.id))throw new Error("Could not set pull request assignees")}async getReviewsForPullRequest(e,r={}){var d,g,
|
|
525
|
+
}`;if(!((d=(p=(l=(await y(this.config,{query:a,variables:{pullRequestGraphQLId:n.graphQLId,assigneeGraphQLIds:i}},r)).body.data)==null?void 0:l.updatePullRequest)==null?void 0:p.pullRequest)!=null&&d.id))throw new Error("Could not set pull request assignees")}async getReviewsForPullRequest(e,r={}){var d,c,g,m;let{repo:{namespace:n,name:o},pullRequestId:i}=e,a=`query getPullRequests(
|
|
526
526
|
$namespace: String!
|
|
527
527
|
$name: String!
|
|
528
528
|
$pullRequestId: Int!
|
|
@@ -574,13 +574,13 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
574
574
|
}
|
|
575
575
|
}
|
|
576
576
|
}
|
|
577
|
-
}`,u=await y(this.config,{query:a,variables:{namespace:n,name:o,pullRequestId:i}},r),l=((
|
|
577
|
+
}`,u=await y(this.config,{query:a,variables:{namespace:n,name:o,pullRequestId:i}},r),l=((c=(d=u.body.data)==null?void 0:d.repository.pullRequest.reviewThreads.nodes)==null?void 0:c.filter(U).reduce((h,R)=>{var v,$;if(!(($=(v=R.comments.nodes)==null?void 0:v[0])!=null&&$.pullRequestReview))return h;let w=R.comments.nodes[0].pullRequestReview,f=us(R);return f&&(h[w.id]||(h[w.id]=[]),h[w.id].push(f)),h},{}))??{};return{data:((m=(g=u.body.data)==null?void 0:g.repository.pullRequest.reviews.nodes)==null?void 0:m.filter(U).filter(h=>l[h.id]).map(h=>({author:h.author?{avatarUrl:h.author.avatarUrl,email:null,name:h.author.login}:null,body:h.body,createdAt:h.publishedAt?new Date(h.publishedAt):null,id:h.databaseId,graphQLId:h.id,reviewComments:l[h.id],url:h.url})))??[]}}async getIssuesAssociatedWithUser(e,r={}){var c;let[n,o]=((c=e.cursor)==null?void 0:c.split(";"))||[void 0,void 0],i=[];e.labelNames&&e.labelNames.forEach(g=>{i.push(`label:"${g}"`)});let[a,u]=await Promise.all([n==="null"?null:this.searchIssues({query:`author:${e.username} ${i.join(" ")}`,cursor:n,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},r),o==="null"?null:this.searchIssues({query:`assignee:${e.username} ${i.join(" ")}`,cursor:o,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},r)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return a==null||a.data.forEach(d),u==null||u.data.forEach(d),{pageInfo:{hasNextPage:(a==null?void 0:a.pageInfo.hasNextPage)||(u==null?void 0:u.pageInfo.hasNextPage)||!1,endCursor:`${(a==null?void 0:a.pageInfo.hasNextPage)&&(a==null?void 0:a.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}async setPullRequestLabels(e,r={}){var u,l,p;let{pullRequest:n,labels:o}=e;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation SetPullRequestLabels($pullRequestGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
|
|
578
578
|
updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, labelIds: $labelGraphQLIds }) {
|
|
579
579
|
pullRequest {
|
|
580
580
|
id
|
|
581
581
|
}
|
|
582
582
|
}
|
|
583
|
-
}`;if(!((p=(l=(u=(await y(this.config,{query:i,variables:{pullRequestGraphQLId:n.graphQLId,labelGraphQLIds:o.map(d=>{if(!d.graphQLId)throw new Error('GitHub requires label "graphQLId" for this function.');return d.graphQLId})}},r)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request labels")}async getIssuesForRepos(e,r={}){let n=
|
|
583
|
+
}`;if(!((p=(l=(u=(await y(this.config,{query:i,variables:{pullRequestGraphQLId:n.graphQLId,labelGraphQLIds:o.map(d=>{if(!d.graphQLId)throw new Error('GitHub requires label "graphQLId" for this function.');return d.graphQLId})}},r)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request labels")}async getIssuesForRepos(e,r={}){let n=pt(e.startQuery||""),{cursor:o,assigneeLogins:i,updatedBefore:a,authorLogin:u,mentionLogin:l,labelNames:p}=e;return e.repos.forEach(d=>{n.push(`repo:${d.namespace}/${d.name}`)}),i&&i.forEach(d=>{n.push(`assignee:${d}`)}),a&&n.push(`updated:<${a}`),u&&n.push(`author:${u}`),l&&n.push(`mentions:${l}`),p&&p.forEach(d=>{n.push(`label:"${d}"`)}),this.searchIssues({query:`sort:updated ${n.join(" ")}`,cursor:o,includeFromArchivedRepos:e.includeFromArchivedRepos,maxPageSize:e.maxPageSize},r)}async closeIssueWithReason(e,r={}){var u,l,p;let{issue:n,reason:o}=e;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation CloseIssueWithReason($issueGraphQLId: ID!, $reason: IssueClosedStateReason!) {
|
|
584
584
|
closeIssue(input: { issueId: $issueGraphQLId, stateReason: $reason }) {
|
|
585
585
|
issue {
|
|
586
586
|
id
|
|
@@ -598,7 +598,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
598
598
|
id
|
|
599
599
|
}
|
|
600
600
|
}
|
|
601
|
-
}`;if(!((l=(u=(a=(await y(this.config,{query:o,variables:{issueGraphQLId:n.graphQLId}},r)).body.data)==null?void 0:a.reopenIssue)==null?void 0:u.issue)!=null&&l.id))throw new Error("Could not reopen issue")}async setIssueLabels(e,r={}){var l,p,d;let{issue:n,labels:o}=e;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=o.map(
|
|
601
|
+
}`;if(!((l=(u=(a=(await y(this.config,{query:o,variables:{issueGraphQLId:n.graphQLId}},r)).body.data)==null?void 0:a.reopenIssue)==null?void 0:u.issue)!=null&&l.id))throw new Error("Could not reopen issue")}async setIssueLabels(e,r={}){var l,p,d;let{issue:n,labels:o}=e;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=o.map(c=>c.graphQLId),a=`mutation SetIssueLabels($issueGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
|
|
602
602
|
updateIssue(input: { id: $issueGraphQLId, labelIds: $labelGraphQLIds }) {
|
|
603
603
|
issue {
|
|
604
604
|
id
|
|
@@ -610,7 +610,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
610
610
|
id
|
|
611
611
|
}
|
|
612
612
|
}
|
|
613
|
-
}`;if(!((p=(l=(u=(await y(this.config,{query:`${i}`,variables:{issueGraphQLId:n.graphQLId,milestoneGraphQLId:(o==null?void 0:o.graphQLId)??null}},r)).body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not set milestone of issue")}async setIssueAssignees(e,r={}){var l,p,d;let{issue:n,assignees:o}=e;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=o.map(
|
|
613
|
+
}`;if(!((p=(l=(u=(await y(this.config,{query:`${i}`,variables:{issueGraphQLId:n.graphQLId,milestoneGraphQLId:(o==null?void 0:o.graphQLId)??null}},r)).body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not set milestone of issue")}async setIssueAssignees(e,r={}){var l,p,d;let{issue:n,assignees:o}=e;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=o.map(c=>{if(!c.graphQLId)throw new Error('GitHub requires assignee "graphQLId" for this function.');return c.graphQLId}),a=`mutation SetIssueAssignees($issueGraphQLId: ID!, $assigneeGraphQLIds: [ID!]!) {
|
|
614
614
|
updateIssue(input: { id: $issueGraphQLId, assigneeIds: $assigneeGraphQLIds }) {
|
|
615
615
|
issue {
|
|
616
616
|
id
|
|
@@ -621,7 +621,7 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
|
|
|
621
621
|
repository(owner: $owner, name: $name) {
|
|
622
622
|
milestones(first: $first, after: $cursor) {
|
|
623
623
|
nodes {
|
|
624
|
-
${
|
|
624
|
+
${we}
|
|
625
625
|
}
|
|
626
626
|
pageInfo {
|
|
627
627
|
endCursor
|
|
@@ -630,12 +630,12 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
|
|
|
630
630
|
}
|
|
631
631
|
}
|
|
632
632
|
}
|
|
633
|
-
`,variables:{owner:n,name:o,cursor:i,first:S}},r);if(!a.body.data)throw new Error(((u=a.body.errors)==null?void 0:u[0].message)||a.statusText||"Unknown error");return{pageInfo:((l=a.body.data.repository.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=a.body.data.repository.milestones)==null?void 0:p.nodes)==null?void 0:d.map(
|
|
633
|
+
`,variables:{owner:n,name:o,cursor:i,first:S}},r);if(!a.body.data)throw new Error(((u=a.body.errors)==null?void 0:u[0].message)||a.statusText||"Unknown error");return{pageInfo:((l=a.body.data.repository.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=a.body.data.repository.milestones)==null?void 0:p.nodes)==null?void 0:d.map(It))??[]}}async getLabelsForRepo(e,r={}){var u,l,p,d;let{repo:{namespace:n,name:o},cursor:i}=e,a=await y(this.config,{query:`
|
|
634
634
|
query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
|
|
635
635
|
repository(owner: $owner, name: $name) {
|
|
636
636
|
labels(first: $first, after: $cursor) {
|
|
637
637
|
nodes {
|
|
638
|
-
${
|
|
638
|
+
${Pe}
|
|
639
639
|
}
|
|
640
640
|
pageInfo {
|
|
641
641
|
endCursor
|
|
@@ -644,7 +644,7 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
|
|
|
644
644
|
}
|
|
645
645
|
}
|
|
646
646
|
}
|
|
647
|
-
`,variables:{owner:n,name:o,cursor:i,first:S}},r);if(!a.body.data)throw new Error(((u=a.body.errors)==null?void 0:u[0].message)||a.statusText||"Unknown error");return{pageInfo:((l=a.body.data.repository.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=a.body.data.repository.labels)==null?void 0:p.nodes)==null?void 0:d.map(
|
|
647
|
+
`,variables:{owner:n,name:o,cursor:i,first:S}},r);if(!a.body.data)throw new Error(((u=a.body.errors)==null?void 0:u[0].message)||a.statusText||"Unknown error");return{pageInfo:((l=a.body.data.repository.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=a.body.data.repository.labels)==null?void 0:p.nodes)==null?void 0:d.map(ft))??[]}}};var ds="https://gitlab.com/api/v4",cs="https://gitlab.com/api/graphql",pr=/\/api\/v\d+$/,dr=s=>{if(s.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.")},Rt=(s,t)=>{let e=t.baseUrl||s.baseUrl;return e?(e=e.replace(/\/$/,""),dr(e),e):ds},gs=(s,t)=>{let e=t.baseUrl||s.baseUrl;return e?(e=e.replace(/\/$/,""),dr(e),pr.test(e)&&(e=e.replace(pr,"")),`${e}/api/graphql`):cs},b=(s,t,e)=>{let r=I(e.token||s.token);return s.request({url:gs(s,e),method:"POST",headers:{...r,"Content-Type":"application/json"},body:JSON.stringify(t)})},qe=s=>s==null?void 0:s.map(t=>`"${t.message}"`).join(", ");var vt=s=>s.split("/").slice(0,-1).join("/"),Et=s=>s.split("/").at(-1)??"",Se=s=>({id:s.id.replace(ee,""),graphQLId:s.id,namespace:vt(s.fullPath),name:Et(s.fullPath),webUrl:s.webUrl}),cr=s=>({id:s.id.replace(ee,""),graphQLId:s.id,httpsUrl:s.httpUrlToRepo,namespace:vt(s.fullPath),name:Et(s.fullPath),sshUrl:s.sshUrlToRepo,webUrl:s.webUrl}),ms={assigned:"assignedMergeRequests",authored:"authoredMergeRequests",reviewRequested:"reviewRequestedMergeRequests"},hs={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"};var fs="gid://gitlab/User/",ee="gid://gitlab/Project/",Is="gid://gitlab/MergeRequest/",Rs="gid://gitlab/Issue/",ys="gid://gitlab/ProjectLabel/",bs="gid://gitlab/Milestone/",ws="gid://gitlab/Ci::Build/",qt=`
|
|
648
648
|
description
|
|
649
649
|
dueDate
|
|
650
650
|
id
|
|
@@ -653,7 +653,7 @@ startDate
|
|
|
653
653
|
state
|
|
654
654
|
title
|
|
655
655
|
webPath
|
|
656
|
-
`,
|
|
656
|
+
`,yt=`
|
|
657
657
|
id
|
|
658
658
|
fullPath
|
|
659
659
|
webUrl
|
|
@@ -669,12 +669,12 @@ username
|
|
|
669
669
|
publicEmail
|
|
670
670
|
avatarUrl
|
|
671
671
|
webUrl
|
|
672
|
-
`,
|
|
672
|
+
`,St=`
|
|
673
673
|
color
|
|
674
674
|
description
|
|
675
675
|
id
|
|
676
676
|
title
|
|
677
|
-
`,
|
|
677
|
+
`,bt=`
|
|
678
678
|
author {
|
|
679
679
|
${z}
|
|
680
680
|
}
|
|
@@ -691,7 +691,7 @@ id
|
|
|
691
691
|
iid
|
|
692
692
|
labels {
|
|
693
693
|
nodes {
|
|
694
|
-
${
|
|
694
|
+
${St}
|
|
695
695
|
}
|
|
696
696
|
}
|
|
697
697
|
state
|
|
@@ -702,9 +702,9 @@ upvotes
|
|
|
702
702
|
userNotesCount
|
|
703
703
|
webUrl
|
|
704
704
|
milestone {
|
|
705
|
-
${
|
|
705
|
+
${qt}
|
|
706
706
|
}
|
|
707
|
-
`,
|
|
707
|
+
`,Ps=`
|
|
708
708
|
stages {
|
|
709
709
|
nodes {
|
|
710
710
|
jobs {
|
|
@@ -720,7 +720,7 @@ stages {
|
|
|
720
720
|
name
|
|
721
721
|
}
|
|
722
722
|
}
|
|
723
|
-
`,
|
|
723
|
+
`,gr=(s,t,e)=>`
|
|
724
724
|
id
|
|
725
725
|
state
|
|
726
726
|
approved
|
|
@@ -765,19 +765,19 @@ reviewers {
|
|
|
765
765
|
mergeStatusEnum
|
|
766
766
|
labels {
|
|
767
767
|
nodes {
|
|
768
|
-
${
|
|
768
|
+
${St}
|
|
769
769
|
}
|
|
770
770
|
}
|
|
771
771
|
${s?"project { id httpUrlToRepo fullPath sshUrlToRepo webUrl archived } sourceProject { id httpUrlToRepo fullPath sshUrlToRepo webUrl }":""}
|
|
772
|
-
${t?`milestone { ${
|
|
773
|
-
${e?`headPipeline { ${
|
|
774
|
-
`,
|
|
772
|
+
${t?`milestone { ${qt} }`:""}
|
|
773
|
+
${e?`headPipeline { ${Ps} }`:""}
|
|
774
|
+
`,Y=s=>`${s.namespace}/${s.name}`,vs=s=>`${s.namespace}/${s.name}`,wt=s=>{var t;return{id:s.id.replace(ee,""),graphQLId:s.id,namespace:vt(s.fullPath),name:Et(s.fullPath),webUrl:s.webUrl,httpsUrl:s.httpUrlToRepo,sshUrl:s.sshUrlToRepo,defaultBranch:(t=s.repository)!=null&&t.rootRef?{name:s.repository.rootRef}:null,permission:null}},Es={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},W=(s,t,e)=>{let r=s.avatarUrl;return!t&&(r!=null&&r.startsWith("/"))?r=`https://gitlab.com${r}`:t&&(r!=null&&r.startsWith("/"))&&e&&(r=`${e.replace(/\/+?$/,"")}${r}`),{id:s.id.replace(fs,""),graphQLId:s.id,name:s.name,username:s.username,email:s.publicEmail??null,avatarUrl:r,url:s.webUrl}},Ct=s=>({color:s.color,description:s.description,id:s.id.replace(ys,""),graphQLId:s.id,name:s.title}),qs=(s,t)=>s?s==="FAILED"&&t?"WARNING":{CANCELED:"CANCELLED",CREATED:"PENDING",FAILED:"FAILED",MANUAL:"OPTIONAL_ACTION_REQUIRED",PENDING:"PENDING",PREPARING:"RUNNING",RUNNING:"RUNNING",SCHEDULED:"PENDING",SKIPPED:"SKIPPED",SUCCESS:"SUCCESS",WAITING_FOR_CALLBACK:"PENDING",WAITING_FOR_RESOURCE:"PENDING"}[s]:null,Ss=(s,t,e)=>{var n;let r={APPROVED:"APPROVED",REQUESTED_CHANGES:"CHANGES_REQUESTED",REVIEWED:"COMMENTED",UNAPPROVED:"REVIEW_REQUESTED",UNREVIEWED:"REVIEW_REQUESTED"};return{reviewer:W(s,t,e),state:(n=s.mergeRequestInteraction)!=null&&n.reviewState?r[s.mergeRequestInteraction.reviewState]:"REVIEW_REQUESTED"}},mr=(s,t,e,r,n)=>{var i,a,u,l,p,d,c,g,m,h,R,w;let o=(i=s.reviewers)!=null&&i.nodes?s.reviewers.nodes.map(f=>Ss(f,r,n)):null;return{id:s.id.replace(Is,""),graphQLId:s.id,title:s.title,number:parseInt(s.iid,10),state:Es[s.state],commentCount:s.userNotesCount||0,upvoteCount:s.upvotes,author:s.author?W(s.author,r,n):null,createdDate:new Date(s.createdAt),isDraft:s.draft,repository:{id:t.id,graphQLId:t.graphQLId,name:t.name,owner:{login:t.namespace},remoteInfo:t.httpsUrl&&t.sshUrl?{cloneUrlHTTPS:t.httpsUrl,cloneUrlSSH:t.sshUrl}:null},headRepository:e?{id:e.id,graphQLId:e.graphQLId,name:e.name,owner:{login:e.namespace},remoteInfo:{cloneUrlHTTPS:e.httpsUrl,cloneUrlSSH:e.sshUrl}}:null,headCommit:{buildStatuses:((l=(u=(a=s.headPipeline)==null?void 0:a.stages)==null?void 0:u.nodes)==null?void 0:l.flatMap(f=>{var v,$;return(($=(v=f.jobs)==null?void 0:v.nodes)==null?void 0:$.map(D=>({completedAt:D.finishedAt?new Date(D.finishedAt):null,description:null,name:D.name??null,state:qs(D.status,D.allowFailure),stage:f.name??null,startedAt:new Date(D.createdAt),url:`${t.webUrl}/-/jobs/${D.id.replace(ws,"")}`})))??[]}))??[]},baseRef:{name:s.targetBranch,oid:((p=s.diffRefs)==null?void 0:p.baseSha)??null},headRef:{name:s.sourceBranch,oid:((d=s.diffRefs)==null?void 0:d.headSha)??null},url:s.webUrl,updatedDate:new Date(s.updatedAt),closedDate:s.mergedAt?new Date(s.mergedAt):null,mergedDate:s.mergedAt?new Date(s.mergedAt):null,assignees:(c=s.assignees)!=null&&c.nodes?s.assignees.nodes.map(f=>W(f,r,n)):null,reviews:o,reviewDecision:s.approved?"APPROVED":H(o),additions:((g=s.diffStatsSummary)==null?void 0:g.additions)||0,deletions:((m=s.diffStatsSummary)==null?void 0:m.deletions)||0,fileCount:((h=s.diffStatsSummary)==null?void 0:h.fileCount)||0,commitCount:s.commitCount||0,mergeableState:hs[s.mergeStatusEnum],milestone:s.milestone?Dt(s.milestone,t.webUrl):null,labels:((w=(R=s.labels)==null?void 0:R.nodes)==null?void 0:w.map(Ct))??[],permissions:null}},Pt=(s,t,e,r)=>{var n,o;return{author:W(s.author,e,r),assignees:s.assignees.nodes.map(i=>W(i,e,r)),commentCount:s.userNotesCount,closedDate:s.closedAt?new Date(s.closedAt):null,createdDate:new Date(s.createdAt),description:s.description,graphQLId:s.id,id:s.id.replace(Rs,""),labels:((o=(n=s.labels)==null?void 0:n.nodes)==null?void 0:o.map(Ct))??[],number:s.iid,repository:{id:t.id.replace(ee,""),graphQLId:t.id,name:t.name,owner:{login:t.namespace}},updatedDate:new Date(s.updatedAt),upvoteCount:s.upvotes,state:{name:s.state,color:null},type:s.type,title:s.title,url:s.webUrl,milestone:s.milestone?Dt(s.milestone,t.webUrl):null}},Dt=(s,t)=>({id:s.id.replace(bs,""),graphQLId:s.id,number:parseInt(s.iid,10),title:s.title,description:s.description,isOpen:s.state==="active",url:`${t}/-/${s.webPath.replace(/.+?\/-\//,"")}`,startDate:s.startDate?new Date(s.startDate):null,dueDate:s.dueDate?new Date(s.dueDate):null}),ae=class extends B{getIsSelfHosted(t){return!!t.baseUrl||!!this.config.baseUrl}async getCurrentUser(t={},e={}){var o;let n=(o=(await b(this.config,{query:`
|
|
775
775
|
query getCurrentUser {
|
|
776
776
|
currentUser {
|
|
777
777
|
${z}
|
|
778
778
|
}
|
|
779
779
|
}
|
|
780
|
-
`},e)).body.data)==null?void 0:o.currentUser;if(!n)throw new Error("Current user not found.");return{data:
|
|
780
|
+
`},e)).body.data)==null?void 0:o.currentUser;if(!n)throw new Error("Current user not found.");return{data:W(n,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}async getUserForCommit(t,e={}){var i,a,u,l;let r=Y(t.repo),o=(l=(u=(a=(i=(await b(this.config,{query:`
|
|
781
781
|
query getUserForCommit($fullPath: ID!, $oid: String!) {
|
|
782
782
|
project(fullPath: $fullPath) {
|
|
783
783
|
repository {
|
|
@@ -799,13 +799,13 @@ query getAccountForEmail($email: String!) {
|
|
|
799
799
|
}
|
|
800
800
|
}
|
|
801
801
|
}
|
|
802
|
-
`,variables:{email:t.email}},e)).body.data)==null?void 0:o.users)==null?void 0:i.nodes)==null?void 0:a[0];if(!n)throw new Error("User not found.");return{data:
|
|
802
|
+
`,variables:{email:t.email}},e)).body.data)==null?void 0:o.users)==null?void 0:i.nodes)==null?void 0:a[0];if(!n)throw new Error("User not found.");return{data:W(n,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}async getAccountForUsername(t,e={}){var o;let n=(o=(await b(this.config,{query:`
|
|
803
803
|
query getAccountForUsername($username: String!) {
|
|
804
804
|
user(username: $username) {
|
|
805
805
|
${z}
|
|
806
806
|
}
|
|
807
807
|
}
|
|
808
|
-
`,variables:{username:t.username}},e)).body.data)==null?void 0:o.user;if(!n)throw new Error("User not found.");return{data:
|
|
808
|
+
`,variables:{username:t.username}},e)).body.data)==null?void 0:o.user;if(!n)throw new Error("User not found.");return{data:W(n,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}async getAccountsForRepo(t,e={}){var u,l,p,d,c,g,m;let{repo:{namespace:r,name:n},cursor:o}=t,i=await b(this.config,{query:`
|
|
809
809
|
query getAccountsForRepo(
|
|
810
810
|
$fullPath: ID!
|
|
811
811
|
$after: String
|
|
@@ -826,22 +826,22 @@ query getAccountsForRepo(
|
|
|
826
826
|
}
|
|
827
827
|
}
|
|
828
828
|
}
|
|
829
|
-
`,variables:{fullPath:`${r}/${n}`,after:o}},e),a=(d=(p=(l=(u=i.body.data)==null?void 0:u.project)==null?void 0:l.projectMembers)==null?void 0:p.nodes)==null?void 0:d.map(h=>h.user).filter(h=>h!==null);return{pageInfo:((m=(
|
|
829
|
+
`,variables:{fullPath:`${r}/${n}`,after:o}},e),a=(d=(p=(l=(u=i.body.data)==null?void 0:u.project)==null?void 0:l.projectMembers)==null?void 0:p.nodes)==null?void 0:d.map(h=>h.user).filter(h=>h!==null);return{pageInfo:((m=(g=(c=i.body.data)==null?void 0:c.project)==null?void 0:g.projectMembers)==null?void 0:m.pageInfo)??{endCursor:null,hasNextPage:!1},data:(a==null?void 0:a.map(h=>W(h,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)))??[]}}async getRepo(t,e={}){var o;let r=Y(t),n=await b(this.config,{query:`
|
|
830
830
|
query getRepo($fullPath: ID!) {
|
|
831
831
|
project(fullPath: $fullPath) {
|
|
832
|
-
${
|
|
832
|
+
${yt}
|
|
833
833
|
}
|
|
834
834
|
}
|
|
835
|
-
`,variables:{fullPath:r}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);return{data:
|
|
835
|
+
`,variables:{fullPath:r}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);return{data:wt(n.body.data.project)}}async getReposBase(t,e={}){let n=t.map(Y).map((u,l)=>`
|
|
836
836
|
getRepo_${l}: project(fullPath: "${u}") {
|
|
837
|
-
${
|
|
837
|
+
${yt}
|
|
838
838
|
}
|
|
839
839
|
`).join(`
|
|
840
840
|
`),o=await b(this.config,{query:`
|
|
841
841
|
query batchGetRepos {
|
|
842
842
|
${n}
|
|
843
843
|
}
|
|
844
|
-
`},e);if(!o.body.data)throw new Error(
|
|
844
|
+
`},e);if(!o.body.data)throw new Error(qe(o.body.errors)||o.statusText||"Unknown error");let i=[],a=[];return t.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?i.push(wt(p)):a.push({input:u})}),{data:i,errors:a}}async getRepos(t,e={}){let r=[];for(let i=0;i<t.length;i+=20)r.push(t.slice(i,i+20));return(await Promise.all(r.map(i=>this.getReposBase(i,e)))).reduce((i,a)=>({data:[...i.data,...a.data],errors:[...i.errors,...a.errors]}),{data:[],errors:[]})}async getReposForCurrentUser(t,e={}){var o,i,a,u,l;let r=await b(this.config,{query:`
|
|
845
845
|
query getReposForCurrentUser($after: String) {
|
|
846
846
|
projects(membership: true first: 100 after: $after) {
|
|
847
847
|
pageInfo {
|
|
@@ -849,11 +849,11 @@ query getReposForCurrentUser($after: String) {
|
|
|
849
849
|
hasNextPage
|
|
850
850
|
}
|
|
851
851
|
nodes {
|
|
852
|
-
${
|
|
852
|
+
${yt}
|
|
853
853
|
}
|
|
854
854
|
}
|
|
855
855
|
}
|
|
856
|
-
`,variables:{after:t.cursor}},e);if(!((o=r.body.data)!=null&&o.projects))throw new Error(
|
|
856
|
+
`,variables:{after:t.cursor}},e);if(!((o=r.body.data)!=null&&o.projects))throw new Error(qe(r.body.errors)||r.statusText||"Unknown error");let n=((a=(i=r.body.data)==null?void 0:i.projects)==null?void 0:a.nodes)||[];return{pageInfo:(l=(u=r.body.data)==null?void 0:u.projects)==null?void 0:l.pageInfo,data:n.map(wt)}}async getRefs(t,e,r={}){var u;let n=Y(e.repo),o=new URL(`${Rt(this.config,r)}/projects/${encodeURIComponent(n)}/repository/${t}`);o.searchParams.set("page",((u=e.page)==null?void 0:u.toString())||"1"),o.searchParams.set("per_page",S.toString());let i=await this.config.request({url:o.toString(),headers:I(r.token||this.config.token)}),a=i.headers["x-next-page"];return{pageInfo:{hasNextPage:!!a,nextPage:a?parseInt(a,10):null},data:i.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(t,e={}){return this.getRefs("branches",t,e)}async getTags(t,e={}){return this.getRefs("tags",t,e)}async getBlame(t,e={}){let r=Y(t.repo),n=new URL(`${Rt(this.config,e)}/projects/${encodeURIComponent(r)}/repository/files/${encodeURIComponent(t.path)}/blame`);n.searchParams.set("ref",t.ref);let o=await this.config.request({url:n.toString(),headers:I(e.token||this.config.token)}),i=0;return{data:{ranges:o.body.map(a=>{let u=i+1;return i+=a.lines.length,{startingLine:u,endingLine:i,commit:{oid:a.commit.id,parentOids:a.commit.parent_ids,authoredDate:new Date(a.commit.authored_date),author:{name:a.commit.author_name,email:a.commit.author_email,avatarUrl:null},committedDate:new Date(a.commit.committed_date),committer:{name:a.commit.committer_name,email:a.commit.committer_email,avatarUrl:null},message:a.commit.message,fileCount:null,additions:null,deletions:null}}})}}}async getPullRequestsForUser(t,e={}){var i;let r=ms[t.association],n=await b(this.config,{query:`
|
|
857
857
|
query getPullRequestsForUser($username: String! $cursor: String $labelNames: [String!]) {
|
|
858
858
|
user(username: $username) {
|
|
859
859
|
${r}(state:opened first:100 after:$cursor labels: $labelNames) {
|
|
@@ -862,12 +862,12 @@ query getPullRequestsForUser($username: String! $cursor: String $labelNames: [St
|
|
|
862
862
|
hasNextPage
|
|
863
863
|
}
|
|
864
864
|
nodes {
|
|
865
|
-
${
|
|
865
|
+
${gr(!0,!0,!0)}
|
|
866
866
|
}
|
|
867
867
|
}
|
|
868
868
|
}
|
|
869
869
|
}
|
|
870
|
-
`,variables:{username:t.username,cursor:t.cursor,labelNames:t.labelNames}},e);if(!n.body.data)throw new Error(
|
|
870
|
+
`,variables:{username:t.username,cursor:t.cursor,labelNames:t.labelNames}},e);if(!n.body.data)throw new Error(qe(n.body.errors)||n.statusText||"Unknown error");if(!n.body.data.user)throw new Error("User not found");let o=n.body.data.user[r];if(!o)throw new Error("Unexpected response");return{pageInfo:o.pageInfo,data:((i=o.nodes)==null?void 0:i.filter(a=>t.includeFromArchivedRepos||!a.project.archived).map(a=>mr(a,cr(a.project),cr(a.sourceProject),this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)))||[]}}async getPullRequestsAssociatedWithUser(t,e={}){var c;let[r,n,o]=((c=t.cursor)==null?void 0:c.split(";"))||[void 0,void 0,void 0],[i,a,u]=await Promise.all([r==="null"?null:this.getPullRequestsForUser({username:t.username,association:"authored",cursor:r,includeFromArchivedRepos:t.includeFromArchivedRepos,labelNames:t.labelNames},e),n==="null"?null:this.getPullRequestsForUser({username:t.username,association:"assigned",cursor:n,includeFromArchivedRepos:t.includeFromArchivedRepos,labelNames:t.labelNames},e),o==="null"?null:this.getPullRequestsForUser({username:t.username,association:"reviewRequested",cursor:o,includeFromArchivedRepos:t.includeFromArchivedRepos,labelNames:t.labelNames},e)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return i==null||i.data.forEach(d),a==null||a.data.forEach(d),u==null||u.data.forEach(d),{pageInfo:{hasNextPage:(i==null?void 0:i.pageInfo.hasNextPage)||(a==null?void 0:a.pageInfo.hasNextPage)||(u==null?void 0:u.pageInfo.hasNextPage)||!1,endCursor:`${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"};${(a==null?void 0:a.pageInfo.hasNextPage)&&(a==null?void 0:a.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}getVariablesForPullRequests(t){let{updatedBefore:e,isDraft:r,authorLogin:n,assigneeLogins:o,labelNames:i,reviewRequestedLogin:a}=t||{},u={},l=[],p=[],d=(c,g,m)=>{l.push(`$${c}: ${m}`),p.push(`${c}: $${c}`),u[c]=g};return e&&d("updatedBefore",e,"Time"),n&&d("authorUsername",n,"String"),o&&d("assigneeUsername",o[0],"String"),i&&d("labelName",i,"[String]"),r!=null&&d("draft",r,"Boolean"),a&&d("reviewerUsername",a,"String"),{variables:u,variableTypes:l,mergeRequestArguments:p}}async getPullRequestsForRepoBase(t,e={},r){var R,w,f;let{cursor:n,repo:o}=t||{},i=Y(o),{variables:a,variableTypes:u,mergeRequestArguments:l}=this.getVariablesForPullRequests(t),p={fullPath:i,...a},d=await b(this.config,{query:`
|
|
871
871
|
query getPullRequestsForRepo(
|
|
872
872
|
$fullPath: ID!
|
|
873
873
|
$after: String
|
|
@@ -892,12 +892,12 @@ query getPullRequestsForRepo(
|
|
|
892
892
|
hasNextPage
|
|
893
893
|
}
|
|
894
894
|
nodes {
|
|
895
|
-
${
|
|
895
|
+
${gr(!1,!0,!0)}
|
|
896
896
|
}
|
|
897
897
|
}
|
|
898
898
|
}
|
|
899
899
|
}
|
|
900
|
-
`,variables:{...p,after:n}},e),
|
|
900
|
+
`,variables:{...p,after:n}},e),c=[],g=(R=d.body.data)==null?void 0:R.project;if(!r&&(g!=null&&g.archived))return{pageInfo:null,data:[]};let m=Se(g||{id:"",fullPath:"",webUrl:""});return(((w=g==null?void 0:g.mergeRequests)==null?void 0:w.nodes)||[]).forEach(v=>{c.push(mr(v,m,null,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl))}),{pageInfo:(f=g==null?void 0:g.mergeRequests)==null?void 0:f.pageInfo,data:c}}async getPullRequestsForRepo(t,e={}){return this.getPullRequestsForRepoBase(t,e,!1)}async getPullRequestsForRepos(t,e={}){let{repos:r,assigneeLogins:n,updatedBefore:o,authorLogin:i,labelNames:a,isDraft:u,reviewRequestedLogin:l}=t;return{data:(await Promise.all(r.map(d=>this.getPullRequestsForRepoBase({repo:d,assigneeLogins:n,updatedBefore:o,authorLogin:i,labelNames:a,isDraft:u,reviewRequestedLogin:l},e,t.includeFromArchivedRepos??!1)))).flatMap(d=>d.data)}}async closePullRequest(t,e={}){var a,u,l;let{pullRequest:r}=t,n=`mutation ClosePullRequest($fullPath: ID!, $pullRequestId: String!) {
|
|
901
901
|
mergeRequestUpdate(input: { projectPath: $fullPath, iid: $pullRequestId, state: CLOSED }) {
|
|
902
902
|
errors,
|
|
903
903
|
mergeRequest {
|
|
@@ -935,7 +935,7 @@ query getPullRequestsForRepo(
|
|
|
935
935
|
id
|
|
936
936
|
}
|
|
937
937
|
}
|
|
938
|
-
}`,a=(u=(await b(this.config,{query:o,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,pullRequestId:r.number.toString(),isDraft:n}},e)).body.data)==null?void 0:u.mergeRequestSetDraft;if(!((l=a==null?void 0:a.mergeRequest)!=null&&l.id)||((p=a==null?void 0:a.errors)==null?void 0:p.length)!==0)throw new Error("Could not set pull request as draft")}async setPullRequestReviewers(t,e={}){var l,p,d;let{pullRequest:r,reviewers:n}=t,o=n.map(
|
|
938
|
+
}`,a=(u=(await b(this.config,{query:o,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,pullRequestId:r.number.toString(),isDraft:n}},e)).body.data)==null?void 0:u.mergeRequestSetDraft;if(!((l=a==null?void 0:a.mergeRequest)!=null&&l.id)||((p=a==null?void 0:a.errors)==null?void 0:p.length)!==0)throw new Error("Could not set pull request as draft")}async setPullRequestReviewers(t,e={}){var l,p,d;let{pullRequest:r,reviewers:n}=t,o=n.map(c=>{if(!c.username)throw new Error('GitLab requires reviewer "username" for this function.');return c.username}),i=`mutation MergeRequestSetReviewers($fullPath: ID!, $pullRequestId: String!, $reviewerUsernames: [String!]!) {
|
|
939
939
|
mergeRequestSetReviewers(input: { projectPath: $fullPath, iid: $pullRequestId, reviewerUsernames: $reviewerUsernames }) {
|
|
940
940
|
errors,
|
|
941
941
|
mergeRequest {
|
|
@@ -949,7 +949,7 @@ query getPullRequestsForRepo(
|
|
|
949
949
|
id
|
|
950
950
|
}
|
|
951
951
|
}
|
|
952
|
-
}`,a=(u=(await b(this.config,{query:o,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,pullRequestId:r.number.toString(),reviewerUserId:n.graphQLId}},e)).body.data)==null?void 0:u.mergeRequestReviewerRereview;if(!((l=a==null?void 0:a.mergeRequest)!=null&&l.id)||((p=a==null?void 0:a.errors)==null?void 0:p.length)!==0)throw new Error("Could not set pull request reviewers")}async reRequestPullRequestReviews(t,e={}){let{pullRequest:r,reviewers:n}=t,o=r.reviews;if(!o)throw new Error('GitLab requires "reviews" for this function.');let i=n.filter(a=>o.find(u=>u.reviewer.graphQLId===a.graphQLId));await Promise.all(i.map(a=>this.reRequestPullRequestReview({pullRequest:r,reviewer:a},e)))}async setPullRequestAssignees(t,e={}){var l,p,d;let{pullRequest:r,assignees:n}=t,o=n.map(
|
|
952
|
+
}`,a=(u=(await b(this.config,{query:o,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,pullRequestId:r.number.toString(),reviewerUserId:n.graphQLId}},e)).body.data)==null?void 0:u.mergeRequestReviewerRereview;if(!((l=a==null?void 0:a.mergeRequest)!=null&&l.id)||((p=a==null?void 0:a.errors)==null?void 0:p.length)!==0)throw new Error("Could not set pull request reviewers")}async reRequestPullRequestReviews(t,e={}){let{pullRequest:r,reviewers:n}=t,o=r.reviews;if(!o)throw new Error('GitLab requires "reviews" for this function.');let i=n.filter(a=>o.find(u=>u.reviewer.graphQLId===a.graphQLId));await Promise.all(i.map(a=>this.reRequestPullRequestReview({pullRequest:r,reviewer:a},e)))}async setPullRequestAssignees(t,e={}){var l,p,d;let{pullRequest:r,assignees:n}=t,o=n.map(c=>{if(!c.username)throw new Error('GitLab requires assignee "username" for this function.');return c.username}),i=`mutation MergeRequestSetAssignees($fullPath: ID!, $pullRequestId: String!, $assigneeUsernames: [String!]!) {
|
|
953
953
|
mergeRequestSetAssignees(input: { projectPath: $fullPath, iid: $pullRequestId, assigneeUsernames: $assigneeUsernames }) {
|
|
954
954
|
errors,
|
|
955
955
|
mergeRequest {
|
|
@@ -962,18 +962,18 @@ query getPullRequestsForRepo(
|
|
|
962
962
|
id
|
|
963
963
|
}
|
|
964
964
|
}
|
|
965
|
-
}`;if(!((p=(l=(u=(await b(this.config,{query:i,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,pullRequestId:r.number.toString(),labelGraphQLIds:o}},e)).body.data)==null?void 0:u.mergeRequestSetLabels)==null?void 0:l.mergeRequest)!=null&&p.id))throw new Error("Could not set pull request labels")}async getIssue(t,e={}){var o,i,a;let r=
|
|
965
|
+
}`;if(!((p=(l=(u=(await b(this.config,{query:i,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,pullRequestId:r.number.toString(),labelGraphQLIds:o}},e)).body.data)==null?void 0:u.mergeRequestSetLabels)==null?void 0:l.mergeRequest)!=null&&p.id))throw new Error("Could not set pull request labels")}async getIssue(t,e={}){var o,i,a;let r=vs(t),n=await b(this.config,{query:`
|
|
966
966
|
query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
|
|
967
967
|
project(fullPath: $projectId) {
|
|
968
968
|
id
|
|
969
969
|
fullPath
|
|
970
970
|
webUrl
|
|
971
971
|
issue(iid: $issueNumber) {
|
|
972
|
-
${
|
|
972
|
+
${bt}
|
|
973
973
|
}
|
|
974
974
|
}
|
|
975
975
|
}
|
|
976
|
-
`,variables:{issueNumber:t.number,projectId:r}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);if(!((a=(i=n.body.data)==null?void 0:i.project)!=null&&a.issue))throw new Error(`Issue ${t.number} not found`);return{data:
|
|
976
|
+
`,variables:{issueNumber:t.number,projectId:r}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);if(!((a=(i=n.body.data)==null?void 0:i.project)!=null&&a.issue))throw new Error(`Issue ${t.number} not found`);return{data:Pt(n.body.data.project.issue,Se(n.body.data.project),this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)}}getVariablesForIssues(t){let{updatedBefore:e,authorLogin:r,assigneeLogins:n,labelNames:o}=t||{},i={},a=[],u=[],l=(p,d,c)=>{a.push(`$${p}: ${c}`),u.push(`${p}: $${p}`),i[p]=d};return e&&l("updatedBefore",e,"Time"),r&&l("authorUsername",r,"String"),n&&l("assigneeUsername",n[0],"String"),o&&l("labelName",o,"[String]"),{variables:i,variableTypes:a,issueArguments:u}}async getIssuesForRepo(t,e={}){var R,w,f;let{cursor:r,repo:n}=t||{},o=Y(n),{variables:i,variableTypes:a,issueArguments:u}=this.getVariablesForIssues(t),l={fullPath:o,...i},p=`
|
|
977
977
|
query GetIssuesFromProject(
|
|
978
978
|
$fullPath: ID!
|
|
979
979
|
$after: String
|
|
@@ -993,7 +993,7 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
|
|
|
993
993
|
${u.length?u.join(" "):""}
|
|
994
994
|
) {
|
|
995
995
|
nodes {
|
|
996
|
-
${
|
|
996
|
+
${bt}
|
|
997
997
|
}
|
|
998
998
|
pageInfo {
|
|
999
999
|
endCursor
|
|
@@ -1001,7 +1001,7 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
|
|
|
1001
1001
|
}
|
|
1002
1002
|
}
|
|
1003
1003
|
}
|
|
1004
|
-
}`,d=await b(this.config,{query:p,variables:{...l,after:r}},e),
|
|
1004
|
+
}`,d=await b(this.config,{query:p,variables:{...l,after:r}},e),c=[],g=(R=d.body.data)==null?void 0:R.project,m=Se(g||{id:"",fullPath:"",webUrl:""});return(((w=g==null?void 0:g.issues)==null?void 0:w.nodes)||[]).forEach(v=>{c.push(Pt(v,m,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl))}),{pageInfo:((f=g==null?void 0:g.issues)==null?void 0:f.pageInfo)??{endCursor:null,hasNextPage:!1},data:c.sort((v,$)=>(v.updatedDate||v.createdDate).getTime()-($.updatedDate||$.createdDate).getTime())}}async getIssuesForRepos(t,e={}){var g,m,h,R,w;let{cursor:r}=t||{},n=t.repoIds.map(f=>f.toString().startsWith(ee)?f:`${ee}${f}`),{variables:o,variableTypes:i,mergeRequestArguments:a}=this.getVariablesForPullRequests(t),u={projectIds:n,...o},l=`
|
|
1005
1005
|
query GetIssuesFromProject(
|
|
1006
1006
|
$projectIds: [ID!]
|
|
1007
1007
|
$after: String
|
|
@@ -1027,12 +1027,12 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
|
|
|
1027
1027
|
${a.length?a.join(" "):""}
|
|
1028
1028
|
) {
|
|
1029
1029
|
nodes {
|
|
1030
|
-
${
|
|
1030
|
+
${bt}
|
|
1031
1031
|
}
|
|
1032
1032
|
}
|
|
1033
1033
|
}
|
|
1034
1034
|
}
|
|
1035
|
-
}`,p=await b(this.config,{query:l,variables:{...u,after:r}},e),d=[];return(((m=(
|
|
1035
|
+
}`,p=await b(this.config,{query:l,variables:{...u,after:r}},e),d=[];return(((m=(g=p.body.data)==null?void 0:g.projects)==null?void 0:m.nodes)||[]).forEach(f=>{var D;if(!t.includeFromArchivedRepos&&f.archived)return;let v=Se(f);(((D=f.issues)==null?void 0:D.nodes)||[]).forEach(E=>d.push(Pt(E,v,this.getIsSelfHosted(e),this.config.baseUrl??e.baseUrl)))}),{pageInfo:((w=(R=(h=p.body)==null?void 0:h.data)==null?void 0:R.projects)==null?void 0:w.pageInfo)??{endCursor:null,hasNextPage:!1},data:d.sort((f,v)=>(f.updatedDate||f.createdDate).getTime()-(v.updatedDate||v.createdDate).getTime())}}async setIssueState(t,e={}){var a,u,l;let{issue:r,state:n}=t;if(!r.repository)throw new Error('GitLab requires "repository" for this function.');let o=`mutation SetIssueState($fullPath: ID!, $issueId: String!, $status: IssueStateEvent!) {
|
|
1036
1036
|
updateIssue(input: { projectPath: $fullPath, iid: $issueId, stateEvent: $status }) {
|
|
1037
1037
|
issue {
|
|
1038
1038
|
id
|
|
@@ -1054,14 +1054,14 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
|
|
|
1054
1054
|
}
|
|
1055
1055
|
}
|
|
1056
1056
|
}
|
|
1057
|
-
}`,i=await b(this.config,{query:o,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,issueId:r.number,milestoneId:(n==null?void 0:n.id)??null}},e),a=(u=i.body.data)==null?void 0:u.updateIssue;if(!((l=a==null?void 0:a.issue)!=null&&l.id)||i.body.errors||((p=a==null?void 0:a.errors)==null?void 0:p.length)!==0)throw new Error("Could not set milestone of issue")}async setIssueAssignees(t,e={}){var l,p,d;let{issue:r,assignees:n}=t;if(!r.repository)throw new Error('GitLab requires "repository" for this function.');let o=n.map(
|
|
1057
|
+
}`,i=await b(this.config,{query:o,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,issueId:r.number,milestoneId:(n==null?void 0:n.id)??null}},e),a=(u=i.body.data)==null?void 0:u.updateIssue;if(!((l=a==null?void 0:a.issue)!=null&&l.id)||i.body.errors||((p=a==null?void 0:a.errors)==null?void 0:p.length)!==0)throw new Error("Could not set milestone of issue")}async setIssueAssignees(t,e={}){var l,p,d;let{issue:r,assignees:n}=t;if(!r.repository)throw new Error('GitLab requires "repository" for this function.');let o=n.map(c=>c.username),i=`mutation SetIssueAssignees($fullPath: ID!, $issueId: String!, $assigneeUsernames: [String!]!) {
|
|
1058
1058
|
issueSetAssignees(input: { projectPath: $fullPath, iid: $issueId, assigneeUsernames: $assigneeUsernames }) {
|
|
1059
1059
|
errors,
|
|
1060
1060
|
issue {
|
|
1061
1061
|
id
|
|
1062
1062
|
}
|
|
1063
1063
|
}
|
|
1064
|
-
}`,u=(l=(await b(this.config,{query:i,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,issueId:r.number,assigneeUsernames:o}},e)).body.data)==null?void 0:l.issueSetAssignees;if(!((p=u==null?void 0:u.issue)!=null&&p.id)||((d=u==null?void 0:u.errors)==null?void 0:d.length)!==0)throw new Error("Could not set issue assignees")}async getMilestonesForRepo(t,e={}){var a,u,l,p,d,g
|
|
1064
|
+
}`,u=(l=(await b(this.config,{query:i,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,issueId:r.number,assigneeUsernames:o}},e)).body.data)==null?void 0:l.issueSetAssignees;if(!((p=u==null?void 0:u.issue)!=null&&p.id)||((d=u==null?void 0:u.errors)==null?void 0:d.length)!==0)throw new Error("Could not set issue assignees")}async getMilestonesForRepo(t,e={}){var a,u,l,p,d,c,g;let{repo:{namespace:r,name:n},cursor:o}=t,i=await b(this.config,{query:`
|
|
1065
1065
|
query getLabelsForRepo(
|
|
1066
1066
|
$fullPath: ID!
|
|
1067
1067
|
$after: String
|
|
@@ -1072,7 +1072,7 @@ query getLabelsForRepo(
|
|
|
1072
1072
|
webUrl
|
|
1073
1073
|
milestones(after: $after) {
|
|
1074
1074
|
nodes {
|
|
1075
|
-
${
|
|
1075
|
+
${qt}
|
|
1076
1076
|
}
|
|
1077
1077
|
pageInfo {
|
|
1078
1078
|
endCursor
|
|
@@ -1081,7 +1081,7 @@ query getLabelsForRepo(
|
|
|
1081
1081
|
}
|
|
1082
1082
|
}
|
|
1083
1083
|
}
|
|
1084
|
-
`,variables:{fullPath:`${r}/${n}`,after:o}},e);return{pageInfo:((l=(u=(a=i.body.data)==null?void 0:a.project)==null?void 0:u.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((
|
|
1084
|
+
`,variables:{fullPath:`${r}/${n}`,after:o}},e);return{pageInfo:((l=(u=(a=i.body.data)==null?void 0:a.project)==null?void 0:u.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=i.body.data)==null?void 0:p.project)==null?void 0:d.milestones)==null?void 0:c.nodes)==null?void 0:g.map(m=>{var h,R;return Dt(m,((R=(h=i.body.data)==null?void 0:h.project)==null?void 0:R.webUrl)||"")}))??[]}}async getLabelsForRepo(t,e={}){var a,u,l,p,d,c,g;let{repo:{namespace:r,name:n},cursor:o}=t,i=await b(this.config,{query:`
|
|
1085
1085
|
query getLabelsForRepo(
|
|
1086
1086
|
$fullPath: ID!
|
|
1087
1087
|
$after: String
|
|
@@ -1091,7 +1091,7 @@ query getLabelsForRepo(
|
|
|
1091
1091
|
) {
|
|
1092
1092
|
labels(after: $after) {
|
|
1093
1093
|
nodes {
|
|
1094
|
-
${
|
|
1094
|
+
${St}
|
|
1095
1095
|
}
|
|
1096
1096
|
pageInfo {
|
|
1097
1097
|
endCursor
|
|
@@ -1100,5 +1100,5 @@ query getLabelsForRepo(
|
|
|
1100
1100
|
}
|
|
1101
1101
|
}
|
|
1102
1102
|
}
|
|
1103
|
-
`,variables:{fullPath:`${r}/${n}`,after:o}},e);return{pageInfo:((l=(u=(a=i.body.data)==null?void 0:a.project)==null?void 0:u.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((
|
|
1104
|
-
OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUser())`];i&&i.forEach(c=>l.push(`labels = "${c}"`));let d=(await s.request({url:`${V(s,r,o)}/rest/api/2/search?jql=${l.join(" AND ")}&startAt=${u}&maxResults=${qe}&fields=${Ct.join(",")}&expand=transitions`,headers:I(r.token||s.token)})).body.issues.map(c=>Dt(c,a,e,o)),g=d.length==qe;return{data:d,pageInfo:{hasNextPage:g,nextPage:g?u+d.length:null}}},cr=async(s,t,e,r={})=>{let{page:n,resourceId:o,jql:i,fields:a}=t||{},u=n??0,l=[...Ct],p=a==null?void 0:a.Sprint;p&&l.push(p);let g=(await s.request({url:`${V(s,r,o)}/rest/api/2/search?jql=${i.join(" AND ")}&startAt=${u}&maxResults=${qe}&fields=${l.join(",")}&expand=transitions`,headers:I(r.token||s.token)})).body.issues.map(m=>Dt(m,a,e,o)),c=g.length==qe;return{data:g,pageInfo:{hasNextPage:c,nextPage:c?u+g.length:null}}},Le=async(s,t,e,r={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:i,labelNames:a,page:u,projectKey:l,resourceId:p,fields:d}=t||{},g=u??0,c=[`project = "${l}"`,"statusCategory != Done"];return o&&c.push(`creator in ("${o}")`),n&&n.length!==0&&c.push(`assignee in ("${n.join('", "')}")`),i&&c.push(`comment ~ "${i}"`),a&&a.forEach(m=>c.push(`labels = "${m}"`)),cr(s,{resourceId:p,jql:c,page:g,fields:d},e,r)},Ae=async(s,t,e,r={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:i,labelNames:a,page:u,projectKeys:l,resourceId:p,fields:d}=t||{},g=u??0,m=["("+l.map(h=>`project = "${h}"`).join(" OR ")+")","statusCategory != Done"];return o&&m.push(`creator in ("${o}")`),n&&n.length!==0&&m.push(`assignee in ("${n.join('", "')}")`),i&&m.push(`comment ~ "${i}"`),a&&a.forEach(h=>m.push(`labels = "${h}"`)),cr(s,{resourceId:p,jql:m,fields:d,page:g},e,r)},$e=async(s,t,e={})=>{let{issue:r,labels:n}=t;if(!r.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{labels:n.map(i=>i.name)}};await s.request({method:"PUT",url:`${V(s,e,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}`,body:JSON.stringify(o),headers:{...I(e.token||s.token),"Content-Type":"application/json"}})},Ge=async(s,t,e={})=>{let{issue:r,components:n}=t;if(!r.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{components:n.map(i=>({id:i.id}))}};await s.request({method:"PUT",url:`${V(s,e,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}`,body:JSON.stringify(o),headers:{...I(e.token||s.token),"Content-Type":"application/json"}})},Te=async(s,t,e={})=>{let{issue:r,status:n}=t;if(!r.project)throw new Error('Jira requires a "project" for this function.');if(!n.id)throw new Error('Jira requires a status "id" for this function.');let o={transition:{id:n.id}};await s.request({method:"POST",url:`${V(s,e,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}/transitions`,body:JSON.stringify(o),headers:{...I(e.token||s.token),"Content-Type":"application/json"}})},Oe=async(s,t,e={})=>{let{resourceId:r,projectIdOrKey:n}=t,o=new URL(`${V(s,e,r)}/rest/api/2/project/${n}/components`);return{data:(await s.request({url:o.toString(),headers:I(e.token||s.token)})).body}};var ae="https://api.atlassian.com/ex/jira",Ut=100,ue=class extends x{constructor(){super(...arguments);this._resourceUrlCache={};this._issueFieldsCache={}}async getIssueFieldsForResource(e,r={}){if(!this._issueFieldsCache[e.resourceId]){let n=await Ce(this.config,e,r);this._issueFieldsCache[e.resourceId]=n.reduce((o,i)=>({...o,[i.name]:i.id}),{})}return this._issueFieldsCache[e.resourceId]??null}async getResourceUrl(e,r={}){var i;let n=r.token||this.config.token;if(!n)return null;let o=this._resourceUrlCache[n];return o?o[e.resourceId]??null:(await this.getJiraResourcesForCurrentUser(r),((i=this._resourceUrlCache[n])==null?void 0:i[e.resourceId])??null)}async getCurrentUserForResource(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r),o=await this.config.request({url:`${r.baseUrl||ae}/${e.resourceId}/rest/api/2/myself`,headers:I(r.token||this.config.token)});return{data:{name:o.body.displayName,email:o.body.emailAddress,avatarUrl:o.body.avatarUrls["48x48"],id:o.body.accountId,username:o.body.displayName,url:n?`${n}/jira/people/${o.body.accountId}`:null}}}async getJiraResourcesForCurrentUser(e={}){let r=await this.config.request({url:`${e.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:I(e.token||this.config.token)}),n=e.token||this.config.token,o=n?this._resourceUrlCache[n]||{}:void 0,i=r.body.map(a=>(o&&(o[a.id]=a.url),{avatarUrl:a.avatarUrl,id:a.id,name:a.name,url:a.url}));return n&&(this._resourceUrlCache[n]=o),{data:i}}async getJiraProjectsForResource(e,r={}){let n=new URL(`${r.baseUrl||ae}/${e.resourceId}/rest/api/2/project/search`);n.searchParams.set("maxResults",Ut.toString()),e.cursor&&n.searchParams.set("startAt",e.cursor);let o=await this.config.request({url:n.toString(),headers:I(r.token||this.config.token)});return{pageInfo:{hasNextPage:o.body.values.length!==0,endCursor:(o.body.startAt+o.body.values.length).toString()},data:o.body.values.map(i=>({id:i.id,key:i.key,name:i.name,resourceId:e.resourceId}))}}async getJiraProjectsForResources(e,r={}){let n=[];return await Promise.all(e.resourceIds.map(async o=>{try{return await Jt(i=>this.getJiraProjectsForResource({resourceId:o,cursor:i},r))}catch{return[]}})).then((...o)=>{o.forEach(i=>{n=n.concat(...i)})}),{data:n}}async getAccountsForJiraProject(e,r={}){let{resourceId:n,projectKey:o,cursor:i}=e,a=await this.getResourceUrl({resourceId:n},r),u=new URL(`${r.baseUrl||ae}/${n}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",Ut.toString()),i&&u.searchParams.set("startAt",i),u.searchParams.set("project",o);let l=await this.config.request({url:u.toString(),headers:I(r.token||this.config.token)});return{pageInfo:{hasNextPage:l.body.length!==0,endCursor:((i?parseInt(i):0)+l.body.length).toString()},data:l.body.filter(p=>p.accountType!=="app"&&p.active).map(p=>Se(p,a,!1))}}async getComponentsForJiraProject(e,r={}){return await Oe(this.config,e,r)}async getIssue(e,r={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},r),o=await this.getResourceUrl({resourceId:e.resourceId},r);return await De(this.config,{...e,fields:n},o,r)}async getIssuesForProject(e,r={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},r),o=await this.getResourceUrl({resourceId:e.resourceId},r);return await Le(this.config,{...e,fields:n},o,r)}async getIssuesForProjects(e,r={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},r),o=await this.getResourceUrl({resourceId:e.resourceId},r);return await Ae(this.config,{...e,fields:n},o,r)}async getIssuesForResourceForCurrentUser(e,r={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},r),o=await this.getResourceUrl({resourceId:e.resourceId},r);return await Ue(this.config,{...e,fields:n},o,r)}async setIssueStatus(e,r={}){await Te(this.config,e,r)}async setIssueAssignee(e,r={}){let{issue:n,assignee:o}=e;if(!n.project)throw new Error('Jira Cloud requires a "project" for this function.');if(!n.project.resourceId)throw new Error('Jira Cloud requires a project "resourceId" for this function.');let i={accountId:o==null?void 0:o.id};await this.config.request({method:"PUT",url:`${r.baseUrl||ae}/${n.project.resourceId}/rest/api/2/issue/${n.id}/assignee`,body:JSON.stringify(i),headers:{...I(r.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(e,r={}){await Ge(this.config,e,r)}async setIssueLabels(e,r={}){await $e(this.config,e,r)}async getLabelsForResource(e,r={}){let{resourceId:n,cursor:o}=e,i=new URL(`${r.baseUrl||ae}/${n}/rest/api/2/label`);i.searchParams.set("maxResults",Ut.toString()),o&&i.searchParams.set("startAt",o);let a=await this.config.request({url:i.toString(),headers:I(r.token||this.config.token)});return{pageInfo:{hasNextPage:!a.body.isLast,endCursor:(a.body.startAt+a.body.values.length).toString()},data:a.body.values.map(u=>({color:null,description:null,id:null,name:u}))}}};var le=class extends Q{constructor(){super(...arguments);this._issueFieldsCache={}}async getIssueFieldsForResource(e={}){let r=(e==null?void 0:e.baseUrl)||this.config.baseUrl||"";if(!this._issueFieldsCache[r]){let n=await Ce(this.config,{},e);this._issueFieldsCache[r]=n.reduce((o,i)=>({...o,[i.name]:i.id}),{})}return this._issueFieldsCache[r]??null}async getCurrentUser(e={}){let r=await this.config.request({url:`${(e==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/myself`,headers:I((e==null?void 0:e.token)||this.config.token)});return{data:{name:r.body.displayName,email:r.body.emailAddress,avatarUrl:r.body.avatarUrls["48x48"],id:r.body.key,username:r.body.displayName,url:null}}}async getJiraProjects(e={}){return{data:(await this.config.request({url:`${(e==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/project`,headers:I((e==null?void 0:e.token)||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getIssue(e,r={}){let n=e.resourceUrl||r.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(r);return await De(this.config,{...e,fields:o},n,r)}async getIssuesForProject(e,r={}){let n=e.resourceUrl||r.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(r);return await Le(this.config,{...e,fields:o},n,r)}async getIssuesForProjects(e,r={}){let n=e.resourceUrl||r.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(r);return await Ae(this.config,{...e,fields:o},n,r)}async getIssuesForResourceForCurrentUser(e,r={}){let n=e.resourceUrl||r.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(r);return await Ue(this.config,{...e,fields:o},n,r)}async setIssueStatus(e,r={}){await Te(this.config,e,r)}async setIssueLabels(e,r={}){await $e(this.config,e,r)}async setIssueComponents(e,r={}){await Ge(this.config,e,r)}async getLabels(e={}){return{data:(await this.config.request({url:`${(e==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/jql/autocompletedata/suggestions?fieldName=labels`,headers:I(e.token||this.config.token)})).body.results.map(({displayName:n})=>({color:null,description:null,id:null,name:n}))}}async getComponentsForJiraProject(e,r={}){return await Oe(this.config,e,r)}};var B="https://api.trello.com",As=1e3,$s=s=>({id:s.id,username:s.username,url:s.url,name:s.fullName,email:s.email,avatarUrl:s.avatarUrl}),Gs=(s,t)=>{let e=new Date(1e3*parseInt(s.id.substring(0,8),16));return{id:s.id,commentCount:s.badges.comments,number:s.idShort.toString(),title:s.name,url:s.url,closedDate:null,createdDate:new Date(e.toISOString()),author:null,updatedDate:new Date(s.dateLastActivity),assignees:s.members.map(r=>({id:r.id,username:r.username,name:r.fullName,email:null,avatarUrl:r.avatarUrl,url:null})),description:null,state:t[s.idList??""]?{id:s.idList,name:t[s.idList].name,color:null}:null,type:null,repository:null,upvoteCount:s.badges.votes,labels:s.labels.map(r=>({color:r.color,description:null,id:r.id,name:r.name}))}},pe=class extends x{async getCurrentUser(t,e={}){let r=await this.config.request({url:`${e.baseUrl||B}/1/members/me?key=${t.appKey}&token=${e.token||this.config.token}`,headers:I(e.token||this.config.token)});return{data:{name:r.body.fullName,email:r.body.email,avatarUrl:r.body.avatarHash?`https://trello-members.s3.amazonaws.com/${r.body.id}/${r.body.avatarHash}/50.png`:null,id:r.body.id,username:r.body.username,url:r.body.url}}}async getBoardsForCurrentUser(t,e={}){return{data:(await this.config.request({url:`${e.baseUrl||B}/1/members/me/boards?fields=name&key=${t.appKey}&token=${e.token||this.config.token}&filter=open`,headers:I(e.token||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getListsForTrelloBoard(t,e={}){let{appKey:r,boardId:n}=t;return{data:(await this.config.request({url:`${e.baseUrl||B}/1/boards/${n}/lists?key=${r}&token=${e.token||this.config.token}`,headers:I(e.token||this.config.token)})).body}}async getAccountForId(t,e={}){let{appKey:r,memberId:n}=t,o=await this.config.request({url:`${e.baseUrl||B}/1/members/${n}/?key=${r}&token=${e.token||this.config.token}`});return{data:$s(o.body)}}async getAccountsForTrelloBoard(t,e={}){let{appKey:r,boardId:n}=t;return{data:(await this.config.request({url:`${e.baseUrl||B}/1/boards/${n}/members?key=${r}&token=${e.token||this.config.token}`,headers:I(e.token||this.config.token)})).body.map(i=>({id:i.id,name:i.fullName,username:i.username,email:null,avatarUrl:null,url:null}))}}async getIssuesForBoard(t,e={}){let r=["-is:archived","sort:edited"],{appKey:n,boardId:o,filterText:i,assigneeLogins:a,labelNamesOrColors:u,trelloBoardListsById:l}=t||{};a&&r.push("@me"),u&&u.forEach(g=>r.push(`label:"${g}"`));let p=`${i?`${i}`:""}${r.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${e.baseUrl||B}/1/search?key=${n}&query=${p}&cards_limit=${As}&token=${e.token||this.config.token}&card_members=true`,headers:I(e.token||this.config.token)})).body.cards.map(g=>Gs(g,l||{}))}}async updateIssue(t,e,r,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||B}/1/cards/${e.id}?key=${t}&token=${n.token||this.config.token}&${r}`,headers:I(n.token||this.config.token)})}async setIssueStatus(t,e={}){let{appKey:r,issue:n,status:o}=t;if(!o.id)throw new Error('Trello requires a status "id" for this function.');let i=`idList=${o.id}`;if(!(await this.updateIssue(r,n,i,e)).body.id)throw new Error("Could not set issue status")}async setIssueAssignees(t,e={}){let{appKey:r,issue:n,assignees:o}=t,i=o.map(l=>l.id),a=`idMembers=${encodeURIComponent(i.join(","))}`;if(!(await this.updateIssue(r,n,a,e)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(t,e={}){let{appKey:r,issue:n,labels:o}=t,i=o.map(u=>u.id).join(",");if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||B}/1/cards/${n.id}?key=${r}&token=${e.token||this.config.token}&idLabels=${encodeURIComponent(i)}`,headers:I(e.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(t,e={}){let{appKey:r,issue:n,archived:o}=t;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||B}/1/cards/${n.id}?key=${r}&token=${e.token||this.config.token}&closed=${o}`,headers:I(e.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async archiveIssue(t,e={}){await this.setIssueArchived({...t,archived:!0},e)}async unArchiveIssue(t,e={}){await this.setIssueArchived({...t,archived:!1},e)}async getLabelsForBoard(t,e={}){let{appKey:r,boardId:n}=t;return{data:(await this.config.request({url:`${e.baseUrl||B}/1/boards/${n}/labels?key=${r}&token=${e.token||this.config.token}`,headers:I(e.token||this.config.token)})).body.map(i=>({color:i.color,description:null,id:i.id,name:i.name}))}}};var xe={};_(xe,{default:()=>Ts});var Ts={};var ke={};_(ke,{default:()=>Os});var Os={};var Ne={};_(Ne,{restApiPullRequestToCommonPullRequest:()=>xs});var xs=s=>se(s);var Ke={};_(Ke,{decode:()=>Qs,decodeV0:()=>Bs,encode:()=>_s,validate:()=>Ns});var U=(e=>(e.Zero="0",e.One="1",e))(U||{}),L=(e=>(e.PullRequest="pr",e.Issue="issue",e))(L||{}),A=(p=>(p.Azure="azure",p.Github="github",p.GithubEnterprise="githubEnterprise",p.Gitlab="gitlab",p.GitlabSelfHosted="gitlabSelfHosted",p.Bitbucket="bitbucket",p.BitbucketServer="bitbucketServer",p.Jira="jira",p.JiraServer="jiraServer",p.Trello="trello",p))(A||{});var _e=class{constructor(){}validate(t){if(!t.organizationName)throw new Error("organizationName is required");if(!t.projectId)throw new Error("projectId is required");if(!t.entityId)throw new Error("issueId is required")}encode(t){if(this.validate(t),!t.organizationName||!t.projectId||!t.entityId)throw new Error("Missing required fields for Azure DevOps issue uniqueId");let e=[];return e.push("azure"),e.push("issue"),e.push("1"),e.push(t.domain||""),e.push(t.organizationName),e.push(t.projectId),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<7)throw new Error("Invalid Azure DevOps issue uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:null,accountOrOrgId:null,organizationName:t[4],projectId:t[5],repoId:null,entityId:t[6]}}};var Qe=class{constructor(){}validate(t){if(!t.organizationName)throw new Error("organizationName is required");if(!t.projectId)throw new Error("projectId is required");if(!t.repoId)throw new Error("repoId is required");if(!t.entityId)throw new Error("entityId is required")}encode(t){if(this.validate(t),!t.organizationName||!t.projectId||!t.repoId||!t.entityId)throw new Error("Missing required fields for Azure DevOps pull request uniqueId");let e=[];return e.push("azure"),e.push("pr"),e.push("1"),e.push(t.domain||""),e.push(t.organizationName),e.push(t.projectId),e.push(t.repoId),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<8)throw new Error("Invalid Azure DevOps pull request uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:null,accountOrOrgId:null,organizationName:t[4],projectId:t[5],repoId:t[6],entityId:t[7]}}};var Be=class{constructor(){}validate(t){if(!t.repoId)throw new Error("repoId is required");if(!t.entityId)throw new Error("issueId is required")}encode(t){if(this.validate(t),!t.repoId||!t.entityId)throw new Error("Missing required fields for Bitbucket DevOps issue uniqueId");let e=[];return e.push(t.provider),e.push("issue"),e.push("1"),t.provider==="bitbucketServer"?e.push(t.domain):e.push(""),e.push(t.repoId),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<6)throw new Error("Invalid Bitbucket DevOps issue uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:t[4],entityId:t[5]}}};var je=class{constructor(){}validate(t){if(!t.repoId)throw new Error("repoId is required");if(!t.entityId)throw new Error("entityId is required")}encode(t){if(this.validate(t),!t.repoId||!t.entityId)throw new Error("Missing required fields for Bitbucket DevOps pull request uniqueId");let e=[];return e.push(t.provider),e.push("pr"),e.push("1"),t.provider==="bitbucketServer"?e.push(t.domain):e.push(""),e.push(t.repoId),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<6)throw new Error("Invalid Bitbucket DevOps pull request uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:t[4],entityId:t[5]}}};var Fe=class{constructor(){}validate(t){if(!t.entityId)throw new Error("entityId is required")}encode(t){if(this.validate(t),!t.entityId)throw new Error("Missing required fields for Github issue uniqueId");let e=[];return e.push(t.provider),e.push("issue"),e.push("1"),t.provider==="githubEnterprise"?e.push(t.domain):e.push(""),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<5)throw new Error("Invalid Github issue uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:t[4]}}};var Me=class{constructor(){}validate(t){if(!t.entityId)throw new Error("entityId is required")}encode(t){if(this.validate(t),!t.entityId)throw new Error("Missing required fields for Github pull request uniqueId");let e=[];return e.push(t.provider),e.push("pr"),e.push("1"),t.provider==="githubEnterprise"?e.push(t.domain):e.push(""),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<5)throw new Error("Invalid Github pull request uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:t[4]}}};var ze=class{constructor(){}validate(t){if(!t.entityId)throw new Error("entityId is required")}encode(t){if(this.validate(t),!t.entityId)throw new Error("Missing required fields for Gitlab issue uniqueId");let e=[];return e.push(t.provider),e.push("issue"),e.push("1"),t.provider==="gitlabSelfHosted"?e.push(t.domain):e.push(""),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<5)throw new Error("Invalid Gitlab issue uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:t[4]}}};var He=class{constructor(){}validate(t){if(!t.entityId)throw new Error("entityId is required")}encode(t){if(this.validate(t),!t.entityId)throw new Error("Missing required fields for Gitlab pull request uniqueId");let e=[];return e.push(t.provider),e.push("pr"),e.push("1"),t.provider==="gitlabSelfHosted"?e.push(t.domain):e.push(""),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<5)throw new Error("Invalid Gitlab pull request uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:t[4]}}};var We=class{constructor(){}validate(t){if(!t.projectId)throw new Error("projectId is required");if(!t.entityId)throw new Error("entityId is required")}encode(t){if(this.validate(t),!t.projectId||!t.entityId)throw new Error("Missing required fields for Jira issue uniqueId");let e=[];return e.push(t.provider),e.push("issue"),e.push("1"),t.provider=="jira"?(e.push(""),e.push(t.resourceId)):(e.push(t.domain),e.push("")),e.push(t.projectId),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<7)throw new Error("Invalid Jira issue uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:t[4]==""?null:t[4],accountOrOrgId:null,organizationName:null,projectId:t[5],repoId:null,entityId:t[6]}}};var Je=class{constructor(){}validate(t){if(!t.accountOrOrgId)throw new Error("accountOrOrgId is required");if(!t.projectId)throw new Error("projectId is required");if(!t.entityId)throw new Error("entityId is required")}encode(t){if(this.validate(t),!t.accountOrOrgId||!t.projectId||!t.entityId)throw new Error("Missing required fields for Trello issue uniqueId");let e=[];return e.push("trello"),e.push("issue"),e.push("1"),e.push(""),e.push(t.accountOrOrgId),e.push(t.projectId),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<7)throw new Error("Invalid Trello issue uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:null,accountOrOrgId:t[4],organizationName:null,projectId:t[5],repoId:null,entityId:t[6]}}};var Ve=(s,t)=>{if(t!=="issue"&&t!=="pr")throw new Error("unknown entityType");switch(s){case"azure":return t==="pr"?new Qe:new _e;case"bitbucket":case"bitbucketServer":return t==="pr"?new je:new Be;case"github":case"githubEnterprise":return t==="pr"?new Me:new Fe;case"gitlab":case"gitlabSelfHosted":return t==="pr"?new He:new ze;case"jira":case"jiraServer":if(t==="pr")throw new Error("EntityType PullRequest is not valid for Jira");return new We;case"trello":if(t==="pr")throw new Error("EntityType PullRequest is not valid for Jira");return new Je;default:throw new Error("unknown provider")}},ks=s=>{if(!s.entityType)throw new Error("entityType is required");if(!s.provider)throw new Error("provider is required");if(!s.entityId)throw new Error("entityID is required")},Ns=s=>{if(s.version==="0"){ks(s);return}Ve(s.provider,s.entityType).validate(s)},_s=s=>Ve(s.provider,s.entityType).encode(s),Qs=s=>{let t=JSON.parse(s);if(!t||!t.length)throw new Error("invalid issue unique id");return Ve(t[0],t[1]).decode(t)},Bs=(s,t,e)=>{if(!e)throw new Error("entityID is required");try{let r=JSON.parse(e);if(!r||!r.length)throw new Error("Invalid pull request uniqueId");let n=[s,t,"0",...r];return Ve(s,t).decode(n)}catch{return{provider:s,entityType:t,version:"0",domain:"",resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e}}};var Xe={};_(Xe,{CHANGES_REQUESTED_ACTION_CATEGORY:()=>Rr,CHANGES_REQUESTED_BUCKET_ID:()=>xt,CONFLICTS_ACTION_CATEGORY:()=>fr,CONFLICTS_BUCKET_ID:()=>Tt,DRAFT_ACTION_CATEGORY:()=>wr,DRAFT_BUCKET_ID:()=>_t,FAILING_CI_ACTION_CATEGORY:()=>hr,FAILING_CI_BUCKET_ID:()=>Gt,NEEDS_MY_REVIEW_ACTION_CATEGORY:()=>Ir,NEEDS_MY_REVIEW_BUCKET_ID:()=>Ot,OTHER_ACTION_CATEGORY:()=>Pr,OTHER_BUCKET_ID:()=>Qt,PINNED_BUCKET_ID:()=>Lt,READY_TO_MERGE_ACTION_CATEGORY:()=>gr,READY_TO_MERGE_BUCKET_ID:()=>At,REVIEWER_COMMENTED_ACTION_CATEGORY:()=>yr,REVIEWER_COMMENTED_BUCKET_ID:()=>kt,SNOOZED_BUCKET_ID:()=>Bt,UNASSIGNED_REVIEWERS_ACTION_CATEGORY:()=>mr,UNASSIGNED_REVIEWERS_BUCKET_ID:()=>$t,WAITING_FOR_REVIEW_ACTION_CATEGORY:()=>br,WAITING_FOR_REVIEW_BUCKET_ID:()=>Nt,getActionablePullRequests:()=>vr,groupPullRequestsIntoBuckets:()=>js});var O=(s,t,e,r)=>({id:s,faIconName:e,name:t,priority:r,pullRequests:[]}),Lt="pinned",At="readyToMerge",$t="unassignedReviewers",Gt="failingCI",Tt="conflicts",Ot="needsMyReview",xt="changesRequested",kt="reviewerCommented",Nt="waitingForReview",_t="draft",Qt="other",Bt="snoozed",gr="readyToMerge",mr="unassignedReviewers",hr="failingCI",fr="conflicts",Ir="needsMyReview",Rr="changesRequested",yr="reviewerCommented",br="waitingForReview",wr="draft",Pr="other",vr=(s,t,e)=>s.map(r=>{var u,l,p,d,g,c,m,h,R,v,f,P,$,C;let o={...r,...{suggestedActionCategory:Pr,priority:1e3,viewer:{canMerge:!1,isAuthor:!1,isAssignee:!1,isReviewer:!1,shouldMerge:!1,shouldAssignReviewer:!1,waitingOnReviews:!1,shouldReview:!1},failingCI:!1,hasConflicts:!1,changeRequestReviewCount:0,codeSuggestionsCount:0,commentReviewCount:0,approvalReviewCount:0}};t&&(o.viewer.isAuthor=((u=r.author)==null?void 0:u.id)===t.id,o.viewer.isAssignee=((l=r.assignees)==null?void 0:l.some(E=>E.id===t.id))??!1,o.viewer.isReviewer=((p=r.reviews)==null?void 0:p.some(E=>E.reviewer.id===t.id))??!1),o.viewer.canMerge=((d=r.permissions)==null?void 0:d.canMerge)??!0,o.hasConflicts=r.mergeableState==="CONFLICTS",o.failingCI=((c=(g=r.headCommit)==null?void 0:g.buildStatuses)==null?void 0:c.some(E=>E.state==="ERROR"||E.state==="FAILED"))??!1,o.commentReviewCount=((m=r.reviews)==null?void 0:m.filter(E=>E.state==="COMMENTED").length)??0,o.approvalReviewCount=((h=r.reviews)==null?void 0:h.filter(E=>E.state==="APPROVED").length)??0,o.changeRequestReviewCount=((R=r.reviews)==null?void 0:R.filter(E=>E.state==="CHANGES_REQUESTED").length)??0;let i=(v=e==null?void 0:e.enrichedItemsByUniqueId)==null?void 0:v[r.uuid];i!=null&&(o.viewer.enrichedItems=i,i.some(E=>E.type==="pin")&&(o.viewer.pinned=!0,o.priority-=800),i.some(E=>E.type==="snooze")&&(o.viewer.snoozed=!0));let a=((P=(f=e==null?void 0:e.codeSuggestionsCountByPrUuid)==null?void 0:f[r.uuid])==null?void 0:P.count)||0;return a&&(o.codeSuggestionsCount=a),(!t||o.viewer.isAuthor||o.viewer.isAssignee&&!o.viewer.isReviewer)&&o.viewer.canMerge&&!o.isDraft&&!o.failingCI&&r.mergeableState==="MERGEABLE"&&(!r.reviewDecision||r.reviewDecision==="APPROVED")&&(o.viewer.shouldMerge=!0,o.suggestedActionCategory=gr),(!t||o.viewer.isAuthor)&&r.isDraft&&(o.suggestedActionCategory=wr),(!t||o.viewer.isAuthor)&&r.reviewDecision==="REVIEW_REQUESTED"&&(o.suggestedActionCategory=br,o.viewer.waitingOnReviews=!0),(!t||o.viewer.isAuthor)&&r.reviewDecision==="COMMENTED"&&(o.suggestedActionCategory=yr),(!t||o.viewer.isAuthor)&&o.failingCI&&(o.suggestedActionCategory=hr),(!t||o.viewer.isAuthor)&&o.hasConflicts&&(o.suggestedActionCategory=fr),(!t||o.viewer.isAuthor)&&(r.reviewDecision==="CHANGES_REQUESTED"||o.codeSuggestionsCount>0)&&(o.suggestedActionCategory=Rr),(!t||o.viewer.isAuthor)&&!(($=r.reviews)!=null&&$.length)&&(o.suggestedActionCategory=mr,o.viewer.shouldAssignReviewer=!0),t&&((C=r.reviews)!=null&&C.some(E=>E.reviewer.id===t.id&&E.state==="REVIEW_REQUESTED"))&&(o.suggestedActionCategory=Ir,o.viewer.shouldReview=!0),o}),js=(s,t,e)=>{let r={pinned:O(Lt,"Pinned","thumbtack",-1),readyToMerge:O(At,"Ready to Merge","code-merge",0),unassignedReviewers:O($t,"Unassigned Reviewers","user-plus",1),failingCI:O(Gt,"Failing CI","circle-x",2),conflicts:O(Tt,"Resolve Conflicts","triangle-exclamation",3),needsMyReview:O(Ot,"Needs My Review","eye",4),changesRequested:O(xt,"Suggested Changes","file-plus",5),reviewerCommented:O(kt,"Reviewer Commented","comment",6),waitingForReview:O(Nt,"Waiting for Review","circle-pause",7),draft:O(_t,"Draft","compass-drafting",8),other:O(Qt,"Other","ellipsis",9),snoozed:O(Bt,"Snoozed","snooze",10)},o=vr(s,t,e).reduce((i,a)=>(i[a.uuid]=a,i),{});return s.forEach(i=>{let a=o[i.uuid],u=!0;if(a.viewer.snoozed){r[Bt].pullRequests.push(i);return}a.viewer.pinned&&r[Lt].pullRequests.push(i),(!t||a.viewer.isAuthor||a.viewer.isAssignee&&!a.viewer.isReviewer)&&!a.isDraft&&a.viewer.canMerge&&a.mergeableState==="MERGEABLE"&&(!i.reviewDecision||i.reviewDecision==="APPROVED")&&(r[At].pullRequests.push(i),u=!1),a.viewer.shouldAssignReviewer&&(r[$t].pullRequests.push(i),u=!1),(!t||a.viewer.isAuthor)&&a.failingCI&&(r[Gt].pullRequests.push(i),u=!1),(!t||a.viewer.isAuthor)&&a.hasConflicts&&(r[Tt].pullRequests.push(i),u=!1),a.viewer.shouldReview&&(r[Ot].pullRequests.push(i),u=!1),(!t||a.viewer.isAuthor)&&(a.reviewDecision==="CHANGES_REQUESTED"||a.codeSuggestionsCount>0)&&(r[xt].pullRequests.push(i),u=!1),(!t||a.viewer.isAuthor)&&a.reviewDecision==="COMMENTED"&&(r[kt].pullRequests.push(i),u=!1),(!t||a.viewer.isAuthor)&&a.reviewDecision==="REVIEW_REQUESTED"&&(r[Nt].pullRequests.push(i),u=!1),a.isDraft&&(r[_t].pullRequests.push(i),u=!1),u&&r[Qt].pullRequests.push(i)}),Object.values(r).forEach(i=>{i.pullRequests.sort((a,u)=>o[a.uuid].priority-o[u.uuid].priority)}),r};var Ye={};_(Ye,{getPullRequestRank:()=>Fs});var Fs=(s,t,e)=>{var i,a,u;let r=0,n,o;return(i=s.reviews)==null||i.forEach(l=>{l.reviewer.id===t&&(n=l.state),l.state==="CHANGES_REQUESTED"?o="CHANGES_REQUESTED":l.state==="APPROVED"&&o!=="CHANGES_REQUESTED"&&(o="APPROVED")}),o||(o="REVIEW_REQUESTED"),((a=s.author)==null?void 0:a.id)===t?r+=1e3:(u=s.assignees)!=null&&u.find(l=>l.id===t)?r+=900:n==="REVIEW_REQUESTED"?r+=800:e&&(r+=700),o==="APPROVED"?s.mergeableState==="MERGEABLE"?r+=100:s.mergeableState==="CONFLICTS"?r+=90:r+=80:o=="CHANGES_REQUESTED"&&(r+=70),r};var Ze={};_(Ze,{default:()=>Ms});var Ms={};var et={};_(et,{default:()=>zs});var zs={};var tt={};_(tt,{default:()=>Hs});var Hs={};var Er=(i=>(i.Conflicts="conflicts",i.Failure="failure",i.NotSet="notSet",i.Queued="queued",i.RejectedByPolicy="rejectedByPolicy",i.Succeeded="succeeded",i))(Er||{});var qr=(e=>(e.Completed="COMPLETED",e.NotPlanned="NOT_PLANNED",e))(qr||{});var Ws=s=>{let t={request:s==null?void 0:s.request};return{azureDevOps:new te({...t,...s==null?void 0:s.azureDevOps}),bitbucket:new re({...t,...s==null?void 0:s.bitbucket}),bitbucketServer:new ne({...t,...s==null?void 0:s.bitbucketServer}),github:new oe({...t,...s==null?void 0:s.github}),gitlab:new ie({...t,...s==null?void 0:s.gitlab}),jira:new ue({...t,...s==null?void 0:s.jira}),jiraServer:new le({...t,...s==null?void 0:s.jiraServer}),trello:new pe({...t,...s==null?void 0:s.trello})}},Js=Ws;var Vs={azureDevOps:xe,bitbucket:ke,bitbucketServer:Ne,github:Ye,gitlab:Ze,gitProvider:Xe,jira:et,trello:tt,entityIdentifier:Ke};
|
|
1103
|
+
`,variables:{fullPath:`${r}/${n}`,after:o}},e);return{pageInfo:((l=(u=(a=i.body.data)==null?void 0:a.project)==null?void 0:u.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=i.body.data)==null?void 0:p.project)==null?void 0:d.labels)==null?void 0:c.nodes)==null?void 0:g.map(Ct))??[]}}};var Cs="https://api.atlassian.com/ex/jira",Ce=100,Ut=["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components","project","fixVersions"],At=(s,t,e,r)=>{var a,u,l,p;let n=s.fields.assignee,o=!r,i=s.fields[(t==null?void 0:t.Sprint)??""]??[];return{id:s.id,commentCount:s.fields.comment.comments.length,number:s.key,title:s.fields.summary,url:e?`${e}/browse/${s.key}`:null,closedDate:null,createdDate:new Date(s.fields.created),author:De(s.fields.creator,e,o),updatedDate:new Date(s.fields.updated),assignees:n?[De(n,e,o)]:[],description:null,repository:null,project:{name:s.fields.project.name,resourceId:r??null,key:s.fields.project.key,namespace:null,id:s.fields.project.id},state:Ls(s.fields.status),statusTransitions:((a=s.transitions)==null?void 0:a.map(Ds))??[],components:((u=s.fields.components)==null?void 0:u.map(Us))??[],type:s.fields.issuetype.name,upvoteCount:((l=s.fields.votes)==null?void 0:l.votes)||0,labels:((p=s.fields.labels)==null?void 0:p.map(d=>({color:null,description:null,id:null,name:d})))??[],sprints:i.map($s),fixVersions:s.fields.fixVersions.map(Gs)}},Ds=s=>{let t;switch(s.to.statusCategory.name){case"To Do":t="TO_DO";break;case"In Progress":t="IN_PROGRESS";break;default:t="DONE";break}return{name:s.name,id:s.id,to:{id:s.to.id,name:s.to.name,color:s.to.statusCategory.colorName,category:t}}},Us=s=>({description:s.description??null,id:s.id,name:s.name}),As=(s,t,e)=>e&&s.name?`${t}/secure/ViewProfile.jspa?name=${encodeURIComponent(s.name)}`:`${t}/jira/people/${s.accountId}`,De=(s,t,e)=>({id:(e?s.key:s.accountId)??"",name:s.displayName,email:s.emailAddress,avatarUrl:s.avatarUrls["48x48"],username:s.displayName,url:As(s,t,e)}),Ls=s=>{let t;switch(s.statusCategory.name){case"To Do":t="TO_DO";break;case"In Progress":t="IN_PROGRESS";break;default:t="DONE";break}return{id:s.id,name:s.name,color:s.statusCategory.colorName,category:t}},$s=s=>({id:s.id.toString(),name:s.name,isActive:s.state==="active",startDate:s.startDate?new Date(s.startDate):null,endDate:s.endDate?new Date(s.endDate):null,completedDate:s.completeDate?new Date(s.completeDate):null}),Gs=s=>({id:s.id,description:s.description,name:s.name,archived:s.archived,released:s.released,releaseDate:s.releaseDate?new Date(s.releaseDate):null}),V=(s,t,e)=>e?`${t.baseUrl||Cs}/${e}`:`${(t==null?void 0:t.baseUrl)||s.baseUrl}`,Ue=async(s,t,e={})=>{let{resourceId:r}=t;return(await s.request({url:`${V(s,e,r)}/rest/api/2/field`,headers:I(e.token||s.token)})).body},Ae=async(s,t,e,r={})=>{let{number:n,resourceId:o,fields:i}=t||{},a=await s.request({url:`${V(s,r,o)}/rest/api/2/issue/${n}?fields=${Ut.join(",")}&expand=transitions`,headers:I(r.token||s.token)});return{data:At(a.body,i,e,o)}},Le=async(s,t,e,r={})=>{let{page:n,resourceId:o,labelNames:i,fields:a}=t||{},u=n??0,l=["statusCategory != Done",`(creator = currentUser() OR assignee = currentUser()
|
|
1104
|
+
OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUser())`];i&&i.forEach(m=>l.push(`labels = "${m}"`));let p=`${l.join(" AND ")} ORDER BY updated DESC`,c=(await s.request({url:`${V(s,r,o)}/rest/api/2/search?jql=${p}&startAt=${u}&maxResults=${Ce}&fields=${Ut.join(",")}&expand=transitions`,headers:I(r.token||s.token)})).body.issues.map(m=>At(m,a,e,o)),g=c.length==Ce;return{data:c,pageInfo:{hasNextPage:g,nextPage:g?u+c.length:null}}},hr=async(s,t,e,r={})=>{let{page:n,resourceId:o,jql:i,fields:a}=t||{},u=n??0,l=[...Ut],p=a==null?void 0:a.Sprint;p&&l.push(p);let c=(await s.request({url:`${V(s,r,o)}/rest/api/2/search?jql=${i.join(" AND ")}&startAt=${u}&maxResults=${Ce}&fields=${l.join(",")}&expand=transitions`,headers:I(r.token||s.token)})).body.issues.map(m=>At(m,a,e,o)),g=c.length==Ce;return{data:c,pageInfo:{hasNextPage:g,nextPage:g?u+c.length:null}}},$e=async(s,t,e,r={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:i,labelNames:a,page:u,projectKey:l,resourceId:p,fields:d}=t||{},c=u??0,g=[`project = "${l}"`,"statusCategory != Done"];return o&&g.push(`creator in ("${o}")`),n&&n.length!==0&&g.push(`assignee in ("${n.join('", "')}")`),i&&g.push(`comment ~ "${i}"`),a&&a.forEach(m=>g.push(`labels = "${m}"`)),hr(s,{resourceId:p,jql:g,page:c,fields:d},e,r)},Ge=async(s,t,e,r={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:i,labelNames:a,page:u,projectKeys:l,resourceId:p,fields:d}=t||{},c=u??0,m=["("+l.map(h=>`project = "${h}"`).join(" OR ")+")","statusCategory != Done"];return o&&m.push(`creator in ("${o}")`),n&&n.length!==0&&m.push(`assignee in ("${n.join('", "')}")`),i&&m.push(`comment ~ "${i}"`),a&&a.forEach(h=>m.push(`labels = "${h}"`)),hr(s,{resourceId:p,jql:m,fields:d,page:c},e,r)},Te=async(s,t,e={})=>{let{issue:r,labels:n}=t;if(!r.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{labels:n.map(i=>i.name)}};await s.request({method:"PUT",url:`${V(s,e,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}`,body:JSON.stringify(o),headers:{...I(e.token||s.token),"Content-Type":"application/json"}})},Oe=async(s,t,e={})=>{let{issue:r,components:n}=t;if(!r.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{components:n.map(i=>({id:i.id}))}};await s.request({method:"PUT",url:`${V(s,e,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}`,body:JSON.stringify(o),headers:{...I(e.token||s.token),"Content-Type":"application/json"}})},xe=async(s,t,e={})=>{let{issue:r,status:n}=t;if(!r.project)throw new Error('Jira requires a "project" for this function.');if(!n.id)throw new Error('Jira requires a status "id" for this function.');let o={transition:{id:n.id}};await s.request({method:"POST",url:`${V(s,e,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}/transitions`,body:JSON.stringify(o),headers:{...I(e.token||s.token),"Content-Type":"application/json"}})},ke=async(s,t,e={})=>{let{resourceId:r,projectIdOrKey:n}=t,o=new URL(`${V(s,e,r)}/rest/api/2/project/${n}/components`);return{data:(await s.request({url:o.toString(),headers:I(e.token||s.token)})).body}};var ue="https://api.atlassian.com/ex/jira",Lt=100,le=class extends x{constructor(){super(...arguments);this._resourceUrlCache={};this._issueFieldsCache={}}async getIssueFieldsForResource(e,r={}){if(!this._issueFieldsCache[e.resourceId]){let n=await Ue(this.config,e,r);this._issueFieldsCache[e.resourceId]=n.reduce((o,i)=>({...o,[i.name]:i.id}),{})}return this._issueFieldsCache[e.resourceId]??null}async getResourceUrl(e,r={}){var i;let n=r.token||this.config.token;if(!n)return null;let o=this._resourceUrlCache[n];return o?o[e.resourceId]??null:(await this.getJiraResourcesForCurrentUser(r),((i=this._resourceUrlCache[n])==null?void 0:i[e.resourceId])??null)}async getCurrentUserForResource(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r),o=await this.config.request({url:`${r.baseUrl||ue}/${e.resourceId}/rest/api/2/myself`,headers:I(r.token||this.config.token)});return{data:{name:o.body.displayName,email:o.body.emailAddress,avatarUrl:o.body.avatarUrls["48x48"],id:o.body.accountId,username:o.body.displayName,url:n?`${n}/jira/people/${o.body.accountId}`:null}}}async getJiraResourcesForCurrentUser(e={}){let r=await this.config.request({url:`${e.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:I(e.token||this.config.token)}),n=e.token||this.config.token,o=n?this._resourceUrlCache[n]||{}:void 0,i=r.body.map(a=>(o&&(o[a.id]=a.url),{avatarUrl:a.avatarUrl,id:a.id,name:a.name,url:a.url}));return n&&(this._resourceUrlCache[n]=o),{data:i}}async getJiraProjectsForResource(e,r={}){let n=new URL(`${r.baseUrl||ue}/${e.resourceId}/rest/api/2/project/search`);n.searchParams.set("maxResults",Lt.toString()),e.cursor&&n.searchParams.set("startAt",e.cursor);let o=await this.config.request({url:n.toString(),headers:I(r.token||this.config.token)});return{pageInfo:{hasNextPage:o.body.values.length!==0,endCursor:(o.body.startAt+o.body.values.length).toString()},data:o.body.values.map(i=>({id:i.id,key:i.key,name:i.name,resourceId:e.resourceId}))}}async getJiraProjectsForResources(e,r={}){let n=[];return await Promise.all(e.resourceIds.map(async o=>{try{return await Xt(i=>this.getJiraProjectsForResource({resourceId:o,cursor:i},r))}catch{return[]}})).then((...o)=>{o.forEach(i=>{n=n.concat(...i)})}),{data:n}}async getAccountsForJiraProject(e,r={}){let{resourceId:n,projectKey:o,cursor:i}=e,a=await this.getResourceUrl({resourceId:n},r),u=new URL(`${r.baseUrl||ue}/${n}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",Lt.toString()),i&&u.searchParams.set("startAt",i),u.searchParams.set("project",o);let l=await this.config.request({url:u.toString(),headers:I(r.token||this.config.token)});return{pageInfo:{hasNextPage:l.body.length!==0,endCursor:((i?parseInt(i):0)+l.body.length).toString()},data:l.body.filter(p=>p.accountType!=="app"&&p.active).map(p=>De(p,a,!1))}}async getComponentsForJiraProject(e,r={}){return await ke(this.config,e,r)}async getIssue(e,r={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},r),o=await this.getResourceUrl({resourceId:e.resourceId},r);return await Ae(this.config,{...e,fields:n},o,r)}async getIssuesForProject(e,r={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},r),o=await this.getResourceUrl({resourceId:e.resourceId},r);return await $e(this.config,{...e,fields:n},o,r)}async getIssuesForProjects(e,r={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},r),o=await this.getResourceUrl({resourceId:e.resourceId},r);return await Ge(this.config,{...e,fields:n},o,r)}async getIssuesForResourceForCurrentUser(e,r={}){let n=await this.getIssueFieldsForResource({resourceId:e.resourceId},r),o=await this.getResourceUrl({resourceId:e.resourceId},r);return await Le(this.config,{...e,fields:n},o,r)}async setIssueStatus(e,r={}){await xe(this.config,e,r)}async setIssueAssignee(e,r={}){let{issue:n,assignee:o}=e;if(!n.project)throw new Error('Jira Cloud requires a "project" for this function.');if(!n.project.resourceId)throw new Error('Jira Cloud requires a project "resourceId" for this function.');let i={accountId:o==null?void 0:o.id};await this.config.request({method:"PUT",url:`${r.baseUrl||ue}/${n.project.resourceId}/rest/api/2/issue/${n.id}/assignee`,body:JSON.stringify(i),headers:{...I(r.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(e,r={}){await Oe(this.config,e,r)}async setIssueLabels(e,r={}){await Te(this.config,e,r)}async getLabelsForResource(e,r={}){let{resourceId:n,cursor:o}=e,i=new URL(`${r.baseUrl||ue}/${n}/rest/api/2/label`);i.searchParams.set("maxResults",Lt.toString()),o&&i.searchParams.set("startAt",o);let a=await this.config.request({url:i.toString(),headers:I(r.token||this.config.token)});return{pageInfo:{hasNextPage:!a.body.isLast,endCursor:(a.body.startAt+a.body.values.length).toString()},data:a.body.values.map(u=>({color:null,description:null,id:null,name:u}))}}};var pe=class extends B{constructor(){super(...arguments);this._issueFieldsCache={}}async getIssueFieldsForResource(e={}){let r=(e==null?void 0:e.baseUrl)||this.config.baseUrl||"";if(!this._issueFieldsCache[r]){let n=await Ue(this.config,{},e);this._issueFieldsCache[r]=n.reduce((o,i)=>({...o,[i.name]:i.id}),{})}return this._issueFieldsCache[r]??null}async getCurrentUser(e={}){let r=await this.config.request({url:`${(e==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/myself`,headers:I((e==null?void 0:e.token)||this.config.token)});return{data:{name:r.body.displayName,email:r.body.emailAddress,avatarUrl:r.body.avatarUrls["48x48"],id:r.body.key,username:r.body.displayName,url:null}}}async getJiraProjects(e={}){return{data:(await this.config.request({url:`${(e==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/project`,headers:I((e==null?void 0:e.token)||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getIssue(e,r={}){let n=e.resourceUrl||r.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(r);return await Ae(this.config,{...e,fields:o},n,r)}async getIssuesForProject(e,r={}){let n=e.resourceUrl||r.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(r);return await $e(this.config,{...e,fields:o},n,r)}async getIssuesForProjects(e,r={}){let n=e.resourceUrl||r.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(r);return await Ge(this.config,{...e,fields:o},n,r)}async getIssuesForResourceForCurrentUser(e,r={}){let n=e.resourceUrl||r.baseUrl||this.config.baseUrl;if(!n)throw new Error('Jira Server requires a "resourceUrl" or "baseUrl" for this function.');let o=await this.getIssueFieldsForResource(r);return await Le(this.config,{...e,fields:o},n,r)}async setIssueStatus(e,r={}){await xe(this.config,e,r)}async setIssueLabels(e,r={}){await Te(this.config,e,r)}async setIssueComponents(e,r={}){await Oe(this.config,e,r)}async getLabels(e={}){return{data:(await this.config.request({url:`${(e==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/jql/autocompletedata/suggestions?fieldName=labels`,headers:I(e.token||this.config.token)})).body.results.map(({displayName:n})=>({color:null,description:null,id:null,name:n}))}}async getComponentsForJiraProject(e,r={}){return await ke(this.config,e,r)}};var Q="https://api.trello.com",Ts=1e3,Os=s=>({id:s.id,username:s.username,url:s.url,name:s.fullName,email:s.email,avatarUrl:s.avatarUrl}),xs=(s,t)=>{let e=new Date(1e3*parseInt(s.id.substring(0,8),16));return{id:s.id,commentCount:s.badges.comments,number:s.idShort.toString(),title:s.name,url:s.url,closedDate:null,createdDate:new Date(e.toISOString()),author:null,updatedDate:new Date(s.dateLastActivity),assignees:s.members.map(r=>({id:r.id,username:r.username,name:r.fullName,email:null,avatarUrl:r.avatarUrl,url:null})),description:null,state:t[s.idList??""]?{id:s.idList,name:t[s.idList].name,color:null}:null,type:null,repository:null,upvoteCount:s.badges.votes,labels:s.labels.map(r=>({color:r.color,description:null,id:r.id,name:r.name}))}},de=class extends x{async getCurrentUser(t,e={}){let r=await this.config.request({url:`${e.baseUrl||Q}/1/members/me?key=${t.appKey}&token=${e.token||this.config.token}`,headers:I(e.token||this.config.token)});return{data:{name:r.body.fullName,email:r.body.email,avatarUrl:r.body.avatarHash?`https://trello-members.s3.amazonaws.com/${r.body.id}/${r.body.avatarHash}/50.png`:null,id:r.body.id,username:r.body.username,url:r.body.url}}}async getBoardsForCurrentUser(t,e={}){return{data:(await this.config.request({url:`${e.baseUrl||Q}/1/members/me/boards?fields=name&key=${t.appKey}&token=${e.token||this.config.token}&filter=open`,headers:I(e.token||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getListsForTrelloBoard(t,e={}){let{appKey:r,boardId:n}=t;return{data:(await this.config.request({url:`${e.baseUrl||Q}/1/boards/${n}/lists?key=${r}&token=${e.token||this.config.token}`,headers:I(e.token||this.config.token)})).body}}async getAccountForId(t,e={}){let{appKey:r,memberId:n}=t,o=await this.config.request({url:`${e.baseUrl||Q}/1/members/${n}/?key=${r}&token=${e.token||this.config.token}`});return{data:Os(o.body)}}async getAccountsForTrelloBoard(t,e={}){let{appKey:r,boardId:n}=t;return{data:(await this.config.request({url:`${e.baseUrl||Q}/1/boards/${n}/members?key=${r}&token=${e.token||this.config.token}`,headers:I(e.token||this.config.token)})).body.map(i=>({id:i.id,name:i.fullName,username:i.username,email:null,avatarUrl:null,url:null}))}}async getIssuesForBoard(t,e={}){let r=["-is:archived","sort:edited"],{appKey:n,boardId:o,filterText:i,assigneeLogins:a,labelNamesOrColors:u,trelloBoardListsById:l}=t||{};a&&r.push("@me"),u&&u.forEach(c=>r.push(`label:"${c}"`));let p=`${i?`${i}`:""}${r.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${e.baseUrl||Q}/1/search?key=${n}&query=${p}&cards_limit=${Ts}&token=${e.token||this.config.token}&card_members=true`,headers:I(e.token||this.config.token)})).body.cards.map(c=>xs(c,l||{}))}}async updateIssue(t,e,r,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||Q}/1/cards/${e.id}?key=${t}&token=${n.token||this.config.token}&${r}`,headers:I(n.token||this.config.token)})}async setIssueStatus(t,e={}){let{appKey:r,issue:n,status:o}=t;if(!o.id)throw new Error('Trello requires a status "id" for this function.');let i=`idList=${o.id}`;if(!(await this.updateIssue(r,n,i,e)).body.id)throw new Error("Could not set issue status")}async setIssueAssignees(t,e={}){let{appKey:r,issue:n,assignees:o}=t,i=o.map(l=>l.id),a=`idMembers=${encodeURIComponent(i.join(","))}`;if(!(await this.updateIssue(r,n,a,e)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(t,e={}){let{appKey:r,issue:n,labels:o}=t,i=o.map(u=>u.id).join(",");if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||Q}/1/cards/${n.id}?key=${r}&token=${e.token||this.config.token}&idLabels=${encodeURIComponent(i)}`,headers:I(e.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(t,e={}){let{appKey:r,issue:n,archived:o}=t;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||Q}/1/cards/${n.id}?key=${r}&token=${e.token||this.config.token}&closed=${o}`,headers:I(e.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async archiveIssue(t,e={}){await this.setIssueArchived({...t,archived:!0},e)}async unArchiveIssue(t,e={}){await this.setIssueArchived({...t,archived:!1},e)}async getLabelsForBoard(t,e={}){let{appKey:r,boardId:n}=t;return{data:(await this.config.request({url:`${e.baseUrl||Q}/1/boards/${n}/labels?key=${r}&token=${e.token||this.config.token}`,headers:I(e.token||this.config.token)})).body.map(i=>({color:i.color,description:null,id:i.id,name:i.name}))}}};var Ne={};_(Ne,{default:()=>ks});var ks={};var _e={};_(_e,{default:()=>Ns});var Ns={};var Be={};_(Be,{restApiPullRequestToCommonPullRequest:()=>_s});var _s=s=>ne(s);var Ye={};_(Ye,{decode:()=>$t,decodeV0:()=>Fs,encode:()=>js,validate:()=>Qs});var A=(e=>(e.Zero="0",e.One="1",e))(A||{}),L=(e=>(e.PullRequest="pr",e.Issue="issue",e))(L||{}),C=(p=>(p.Azure="azure",p.Github="github",p.GithubEnterprise="githubEnterprise",p.Gitlab="gitlab",p.GitlabSelfHosted="gitlabSelfHosted",p.Bitbucket="bitbucket",p.BitbucketServer="bitbucketServer",p.Jira="jira",p.JiraServer="jiraServer",p.Trello="trello",p))(C||{});var Qe=class{constructor(){}validate(t){if(!t.organizationName)throw new Error("organizationName is required");if(!t.projectId)throw new Error("projectId is required");if(!t.entityId)throw new Error("issueId is required")}encode(t){if(this.validate(t),!t.organizationName||!t.projectId||!t.entityId)throw new Error("Missing required fields for Azure DevOps issue uniqueId");let e=[];return e.push("azure"),e.push("issue"),e.push("1"),e.push(t.domain||""),e.push(t.organizationName),e.push(t.projectId),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<7)throw new Error("Invalid Azure DevOps issue uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:null,accountOrOrgId:null,organizationName:t[4],projectId:t[5],repoId:null,entityId:t[6]}}};var je=class{constructor(){}validate(t){if(!t.organizationName)throw new Error("organizationName is required");if(!t.projectId)throw new Error("projectId is required");if(!t.repoId)throw new Error("repoId is required");if(!t.entityId)throw new Error("entityId is required")}encode(t){if(this.validate(t),!t.organizationName||!t.projectId||!t.repoId||!t.entityId)throw new Error("Missing required fields for Azure DevOps pull request uniqueId");let e=[];return e.push("azure"),e.push("pr"),e.push("1"),e.push(t.domain||""),e.push(t.organizationName),e.push(t.projectId),e.push(t.repoId),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<8)throw new Error("Invalid Azure DevOps pull request uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:null,accountOrOrgId:null,organizationName:t[4],projectId:t[5],repoId:t[6],entityId:t[7]}}};var Fe=class{constructor(){}validate(t){if(!t.repoId)throw new Error("repoId is required");if(!t.entityId)throw new Error("issueId is required")}encode(t){if(this.validate(t),!t.repoId||!t.entityId)throw new Error("Missing required fields for Bitbucket DevOps issue uniqueId");let e=[];return e.push(t.provider),e.push("issue"),e.push("1"),t.provider==="bitbucketServer"?e.push(t.domain):e.push(""),e.push(t.repoId),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<6)throw new Error("Invalid Bitbucket DevOps issue uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:t[4],entityId:t[5]}}};var Me=class{constructor(){}validate(t){if(!t.repoId)throw new Error("repoId is required");if(!t.entityId)throw new Error("entityId is required")}encode(t){if(this.validate(t),!t.repoId||!t.entityId)throw new Error("Missing required fields for Bitbucket DevOps pull request uniqueId");let e=[];return e.push(t.provider),e.push("pr"),e.push("1"),t.provider==="bitbucketServer"?e.push(t.domain):e.push(""),e.push(t.repoId),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<6)throw new Error("Invalid Bitbucket DevOps pull request uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:t[4],entityId:t[5]}}};var ze=class{constructor(){}validate(t){if(!t.entityId)throw new Error("entityId is required")}encode(t){if(this.validate(t),!t.entityId)throw new Error("Missing required fields for Github issue uniqueId");let e=[];return e.push(t.provider),e.push("issue"),e.push("1"),t.provider==="githubEnterprise"?e.push(t.domain):e.push(""),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<5)throw new Error("Invalid Github issue uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:t[4]}}};var We=class{constructor(){}validate(t){if(!t.entityId)throw new Error("entityId is required")}encode(t){if(this.validate(t),!t.entityId)throw new Error("Missing required fields for Github pull request uniqueId");let e=[];return e.push(t.provider),e.push("pr"),e.push("1"),t.provider==="githubEnterprise"?e.push(t.domain):e.push(""),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<5)throw new Error("Invalid Github pull request uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:t[4]}}};var He=class{constructor(){}validate(t){if(!t.entityId)throw new Error("entityId is required")}encode(t){if(this.validate(t),!t.entityId)throw new Error("Missing required fields for Gitlab issue uniqueId");let e=[];return e.push(t.provider),e.push("issue"),e.push("1"),t.provider==="gitlabSelfHosted"?e.push(t.domain):e.push(""),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<5)throw new Error("Invalid Gitlab issue uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:t[4]}}};var Je=class{constructor(){}validate(t){if(!t.entityId)throw new Error("entityId is required")}encode(t){if(this.validate(t),!t.entityId)throw new Error("Missing required fields for Gitlab pull request uniqueId");let e=[];return e.push(t.provider),e.push("pr"),e.push("1"),t.provider==="gitlabSelfHosted"?e.push(t.domain):e.push(""),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<5)throw new Error("Invalid Gitlab pull request uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:t[4]}}};var Ve=class{constructor(){}validate(t){if(!t.projectId)throw new Error("projectId is required");if(!t.entityId)throw new Error("entityId is required")}encode(t){if(this.validate(t),!t.projectId||!t.entityId)throw new Error("Missing required fields for Jira issue uniqueId");let e=[];return e.push(t.provider),e.push("issue"),e.push("1"),t.provider=="jira"?(e.push(""),e.push(t.resourceId)):(e.push(t.domain),e.push("")),e.push(t.projectId),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<7)throw new Error("Invalid Jira issue uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:t[4]==""?null:t[4],accountOrOrgId:null,organizationName:null,projectId:t[5],repoId:null,entityId:t[6]}}};var Ke=class{constructor(){}validate(t){if(!t.accountOrOrgId)throw new Error("accountOrOrgId is required");if(!t.projectId)throw new Error("projectId is required");if(!t.entityId)throw new Error("entityId is required")}encode(t){if(this.validate(t),!t.accountOrOrgId||!t.projectId||!t.entityId)throw new Error("Missing required fields for Trello issue uniqueId");let e=[];return e.push("trello"),e.push("issue"),e.push("1"),e.push(""),e.push(t.accountOrOrgId),e.push(t.projectId),e.push(t.entityId),JSON.stringify(e)}decode(t){if(t.length<7)throw new Error("Invalid Trello issue uniqueId, check version");return{provider:t[0],entityType:t[1],version:t[2],domain:t[3]==""?null:t[3],resourceId:null,accountOrOrgId:t[4],organizationName:null,projectId:t[5],repoId:null,entityId:t[6]}}};var Xe=(s,t)=>{if(t!=="issue"&&t!=="pr")throw new Error("unknown entityType");switch(s){case"azure":return t==="pr"?new je:new Qe;case"bitbucket":case"bitbucketServer":return t==="pr"?new Me:new Fe;case"github":case"githubEnterprise":return t==="pr"?new We:new ze;case"gitlab":case"gitlabSelfHosted":return t==="pr"?new Je:new He;case"jira":case"jiraServer":if(t==="pr")throw new Error("EntityType PullRequest is not valid for Jira");return new Ve;case"trello":if(t==="pr")throw new Error("EntityType PullRequest is not valid for Jira");return new Ke;default:throw new Error("unknown provider")}},Bs=s=>{if(!s.entityType)throw new Error("entityType is required");if(!s.provider)throw new Error("provider is required");if(!s.entityId)throw new Error("entityID is required")},Qs=s=>{if(s.version==="0"){Bs(s);return}Xe(s.provider,s.entityType).validate(s)},js=s=>Xe(s.provider,s.entityType).encode(s),$t=s=>{let t=JSON.parse(s);if(!t||!t.length)throw new Error("invalid issue unique id");return Xe(t[0],t[1]).decode(t)},Fs=(s,t,e)=>{if(!e)throw new Error("entityID is required");try{let r=JSON.parse(e);if(!r||!r.length)throw new Error("Invalid pull request uniqueId");let n=[s,t,"0",...r];return Xe(s,t).decode(n)}catch{return{provider:s,entityType:t,version:"0",domain:"",resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e}}};var Ze={};_(Ze,{CHANGES_REQUESTED_ACTION_CATEGORY:()=>wr,CHANGES_REQUESTED_BUCKET_ID:()=>_t,CONFLICTS_ACTION_CATEGORY:()=>yr,CONFLICTS_BUCKET_ID:()=>kt,DRAFT_ACTION_CATEGORY:()=>Er,DRAFT_BUCKET_ID:()=>jt,FAILING_CI_ACTION_CATEGORY:()=>Rr,FAILING_CI_BUCKET_ID:()=>xt,NEEDS_MY_REVIEW_ACTION_CATEGORY:()=>br,NEEDS_MY_REVIEW_BUCKET_ID:()=>Nt,OTHER_ACTION_CATEGORY:()=>qr,OTHER_BUCKET_ID:()=>Ft,PINNED_BUCKET_ID:()=>Gt,READY_TO_MERGE_ACTION_CATEGORY:()=>fr,READY_TO_MERGE_BUCKET_ID:()=>Tt,REVIEWER_COMMENTED_ACTION_CATEGORY:()=>Pr,REVIEWER_COMMENTED_BUCKET_ID:()=>Bt,SNOOZED_BUCKET_ID:()=>Mt,UNASSIGNED_REVIEWERS_ACTION_CATEGORY:()=>Ir,UNASSIGNED_REVIEWERS_BUCKET_ID:()=>Ot,WAITING_FOR_REVIEW_ACTION_CATEGORY:()=>vr,WAITING_FOR_REVIEW_BUCKET_ID:()=>Qt,getActionablePullRequests:()=>Sr,groupPullRequestsByAssignee:()=>Ws,groupPullRequestsByAuthor:()=>Hs,groupPullRequestsByGitKrakenTeam:()=>Xs,groupPullRequestsByRepo:()=>zs,groupPullRequestsByReviewer:()=>Js,groupPullRequestsByWorkspace:()=>Ks,groupPullRequestsIntoBuckets:()=>Ms});var O=(s,t,e,r)=>({id:s,faIconName:e,name:t,priority:r,pullRequests:[]}),Gt="pinned",Tt="readyToMerge",Ot="unassignedReviewers",xt="failingCI",kt="conflicts",Nt="needsMyReview",_t="changesRequested",Bt="reviewerCommented",Qt="waitingForReview",jt="draft",Ft="other",Mt="snoozed",fr="readyToMerge",Ir="unassignedReviewers",Rr="failingCI",yr="conflicts",br="needsMyReview",wr="changesRequested",Pr="reviewerCommented",vr="waitingForReview",Er="draft",qr="other",Sr=(s,t,e)=>s.map(r=>{var u,l,p,d,c,g,m,h,R,w,f,v,$,D;let o={...r,...{suggestedActionCategory:qr,priority:1e3,viewer:{canMerge:!1,isAuthor:!1,isAssignee:!1,isReviewer:!1,shouldMerge:!1,shouldAssignReviewer:!1,waitingOnReviews:!1,shouldReview:!1},failingCI:!1,hasConflicts:!1,changeRequestReviewCount:0,codeSuggestionsCount:0,commentReviewCount:0,approvalReviewCount:0}};t&&(o.viewer.isAuthor=((u=r.author)==null?void 0:u.id)===t.id,o.viewer.isAssignee=((l=r.assignees)==null?void 0:l.some(E=>E.id===t.id))??!1,o.viewer.isReviewer=((p=r.reviews)==null?void 0:p.some(E=>E.reviewer.id===t.id))??!1),o.viewer.canMerge=((d=r.permissions)==null?void 0:d.canMerge)??!0,o.hasConflicts=r.mergeableState==="CONFLICTS",o.failingCI=((g=(c=r.headCommit)==null?void 0:c.buildStatuses)==null?void 0:g.some(E=>E.state==="ERROR"||E.state==="FAILED"))??!1,o.commentReviewCount=((m=r.reviews)==null?void 0:m.filter(E=>E.state==="COMMENTED").length)??0,o.approvalReviewCount=((h=r.reviews)==null?void 0:h.filter(E=>E.state==="APPROVED").length)??0,o.changeRequestReviewCount=((R=r.reviews)==null?void 0:R.filter(E=>E.state==="CHANGES_REQUESTED").length)??0;let i=(w=e==null?void 0:e.enrichedItemsByUniqueId)==null?void 0:w[r.uuid];i!=null&&(o.viewer.enrichedItems=i,i.some(E=>E.type==="pin")&&(o.viewer.pinned=!0,o.priority-=800),i.some(E=>E.type==="snooze")&&(o.viewer.snoozed=!0));let a=((v=(f=e==null?void 0:e.codeSuggestionsCountByPrUuid)==null?void 0:f[r.uuid])==null?void 0:v.count)||0;return a&&(o.codeSuggestionsCount=a),(!t||o.viewer.isAuthor||o.viewer.isAssignee&&!o.viewer.isReviewer)&&o.viewer.canMerge&&!o.isDraft&&!o.failingCI&&r.mergeableState==="MERGEABLE"&&(!r.reviewDecision||r.reviewDecision==="APPROVED")&&(o.viewer.shouldMerge=!0,o.suggestedActionCategory=fr),(!t||o.viewer.isAuthor)&&r.isDraft&&(o.suggestedActionCategory=Er),(!t||o.viewer.isAuthor)&&r.reviewDecision==="REVIEW_REQUESTED"&&(o.suggestedActionCategory=vr,o.viewer.waitingOnReviews=!0),(!t||o.viewer.isAuthor)&&r.reviewDecision==="COMMENTED"&&(o.suggestedActionCategory=Pr),(!t||o.viewer.isAuthor)&&o.failingCI&&(o.suggestedActionCategory=Rr),(!t||o.viewer.isAuthor)&&o.hasConflicts&&(o.suggestedActionCategory=yr),(!t||o.viewer.isAuthor)&&(r.reviewDecision==="CHANGES_REQUESTED"||o.codeSuggestionsCount>0)&&(o.suggestedActionCategory=wr),(!t||o.viewer.isAuthor)&&!(($=r.reviews)!=null&&$.length)&&(o.suggestedActionCategory=Ir,o.viewer.shouldAssignReviewer=!0),t&&((D=r.reviews)!=null&&D.some(E=>E.reviewer.id===t.id&&E.state==="REVIEW_REQUESTED"))&&(o.suggestedActionCategory=br,o.viewer.shouldReview=!0),o}),Ms=(s,t,e)=>{let r={pinned:O(Gt,"Pinned","thumbtack",-1),readyToMerge:O(Tt,"Ready to Merge","code-merge",0),unassignedReviewers:O(Ot,"Unassigned Reviewers","user-plus",1),failingCI:O(xt,"Failing CI","circle-x",2),conflicts:O(kt,"Resolve Conflicts","triangle-exclamation",3),needsMyReview:O(Nt,"Needs My Review","eye",4),changesRequested:O(_t,"Suggested Changes","file-plus",5),reviewerCommented:O(Bt,"Reviewer Commented","comment",6),waitingForReview:O(Qt,"Waiting for Review","circle-pause",7),draft:O(jt,"Draft","compass-drafting",8),other:O(Ft,"Other","ellipsis",9),snoozed:O(Mt,"Snoozed","snooze",10)},o=Sr(s,t,e).reduce((i,a)=>(i[a.uuid]=a,i),{});return s.forEach(i=>{let a=o[i.uuid],u=!0;if(a.viewer.snoozed){r[Mt].pullRequests.push(i);return}a.viewer.pinned&&r[Gt].pullRequests.push(i),(!t||a.viewer.isAuthor||a.viewer.isAssignee&&!a.viewer.isReviewer)&&!a.isDraft&&a.viewer.canMerge&&a.mergeableState==="MERGEABLE"&&(!i.reviewDecision||i.reviewDecision==="APPROVED")&&(r[Tt].pullRequests.push(i),u=!1),a.viewer.shouldAssignReviewer&&(r[Ot].pullRequests.push(i),u=!1),(!t||a.viewer.isAuthor)&&a.failingCI&&(r[xt].pullRequests.push(i),u=!1),(!t||a.viewer.isAuthor)&&a.hasConflicts&&(r[kt].pullRequests.push(i),u=!1),a.viewer.shouldReview&&(r[Nt].pullRequests.push(i),u=!1),(!t||a.viewer.isAuthor)&&(a.reviewDecision==="CHANGES_REQUESTED"||a.codeSuggestionsCount>0)&&(r[_t].pullRequests.push(i),u=!1),(!t||a.viewer.isAuthor)&&a.reviewDecision==="COMMENTED"&&(r[Bt].pullRequests.push(i),u=!1),(!t||a.viewer.isAuthor)&&a.reviewDecision==="REVIEW_REQUESTED"&&(r[Qt].pullRequests.push(i),u=!1),a.isDraft&&(r[jt].pullRequests.push(i),u=!1),u&&r[Ft].pullRequests.push(i)}),Object.values(r).forEach(i=>{i.pullRequests.sort((a,u)=>o[a.uuid].priority-o[u.uuid].priority)}),r},zs=s=>{let t={};return s.forEach(e=>{let r=e.repository.id;t[r]?t[r].pullRequests.push(e):t[r]={name:e.repository.name,priority:0,pullRequests:[e],id:r}}),X(t)},Ws=s=>{let t="internal-no-assignees",e={[t]:{name:"No assignees",priority:-1,pullRequests:[],id:t,faIconName:"user-slash"}};return s.forEach(r=>{r.assignees&&r.assignees.length?r.assignees.forEach(n=>{let o=n.id;e[o]?e[o].pullRequests.push(r):e[o]={accountData:n,name:ge(n,`Unknown Assignee ${Object.keys(e).length}`),priority:0,pullRequests:[r],id:o}}):e[t].pullRequests.push(r)}),X(e)},Hs=s=>{let t="internal-no-author",e={[t]:{name:"No author",priority:-1,pullRequests:[],id:t,faIconName:"user-slash"}};return s.forEach(r=>{if(r.author){let n=r.author.id;e[n]?e[n].pullRequests.push(r):e[n]={accountData:r.author,name:ge(r.author,`Unknown Author ${Object.keys(e).length}`),priority:0,pullRequests:[r],id:n}}else e[t].pullRequests.push(r)}),X(e)},Js=s=>{let t="internal-no-reviewer",e={[t]:{name:"No reviewers",priority:-1,pullRequests:[],id:t,faIconName:"user-slash"}};return s.forEach(r=>{r.reviews&&r.reviews.length?r.reviews.forEach(n=>{let o=n.reviewer.id;e[o]?e[o].pullRequests.push(r):e[o]={accountData:n.reviewer,name:ge(n.reviewer,`Unknown Reviewer ${Object.keys(e).length}`),priority:0,pullRequests:[r],id:o}}):e[t].pullRequests.push(r)}),X(e)},Vs=s=>{var t;return s.azureProject?[`${s.azureProject}-${s.azureOrganizationId}`]:((t=s.providerData)==null?void 0:t.repositories.nodes.map(e=>`${s.provider}-${e.repositoryId}`))??[]},Ks=(s,t)=>{let e="internal-no-workspace",r={[e]:{name:"No workspace",priority:-1,pullRequests:[],id:e,faIconName:"folder-xmark"}};if(t.length){let n=t.reduce((o,i)=>(Vs(i).forEach(u=>{o[u]?o[u].push(i):o[u]=[i]}),o),{});s.forEach(o=>{let{provider:i}=$t(o.uuid),a=i==="github"?o.repository.graphQLId:o.repository.id,u=i==="azure"?[`${i}-${a}`,`${o.repository.project}-${o.repository.owner.login}`]:[`${i}-${a}`],l=!1,p=u.reduce((d,c)=>n[c]?d.concat(n[c]):d,[]);p!=null&&p.length&&p.forEach(d=>{l=!0;let c=d.id;r[c]?r[c].pullRequests.push(o):r[c]={name:d.name,priority:0,pullRequests:[o],id:c,faIconName:"folder"}}),l||r[e].pullRequests.push(o)})}else r[e].pullRequests=s;return X(r)},Xs=(s,t,e,r)=>{let n="internal-no-team",o={[n]:{name:"No team",priority:-1,pullRequests:[],id:n}};return r.length?s.forEach(i=>{var l,p,d;let a=!1,u=new Set;u.add((l=i.author)==null?void 0:l.id),(p=i.assignees)==null||p.forEach(c=>u.add(c.id)),(d=i.reviews)==null||d.forEach(c=>u.add(c.reviewer.id)),r.forEach(c=>{var m;if((m=c.members)==null?void 0:m.some(h=>{var w,f;let R=(f=(w=t[h.id])==null?void 0:w[e])==null?void 0:f.providerID;return R&&u.has(R)})){a=!0;let h=c.id;o[h]?o[h].pullRequests.push(i):o[h]={name:c.name,priority:0,pullRequests:[i],id:h,teamData:c}}}),a||o[n].pullRequests.push(i)}):o[n].pullRequests=s,X(o)};var et={};_(et,{getPullRequestRank:()=>Ys});var Ys=(s,t,e)=>{var i,a,u;let r=0,n,o;return(i=s.reviews)==null||i.forEach(l=>{l.reviewer.id===t&&(n=l.state),l.state==="CHANGES_REQUESTED"?o="CHANGES_REQUESTED":l.state==="APPROVED"&&o!=="CHANGES_REQUESTED"&&(o="APPROVED")}),o||(o="REVIEW_REQUESTED"),((a=s.author)==null?void 0:a.id)===t?r+=1e3:(u=s.assignees)!=null&&u.find(l=>l.id===t)?r+=900:n==="REVIEW_REQUESTED"?r+=800:e&&(r+=700),o==="APPROVED"?s.mergeableState==="MERGEABLE"?r+=100:s.mergeableState==="CONFLICTS"?r+=90:r+=80:o=="CHANGES_REQUESTED"&&(r+=70),r};var tt={};_(tt,{default:()=>Zs});var Zs={};var rt={};_(rt,{default:()=>en});var en={};var st={};_(st,{default:()=>tn});var tn={};var Cr=(i=>(i.Conflicts="conflicts",i.Failure="failure",i.NotSet="notSet",i.Queued="queued",i.RejectedByPolicy="rejectedByPolicy",i.Succeeded="succeeded",i))(Cr||{});var Dr=(e=>(e.Completed="COMPLETED",e.NotPlanned="NOT_PLANNED",e))(Dr||{});var rn=s=>{let t={request:s==null?void 0:s.request};return{azureDevOps:new re({...t,...s==null?void 0:s.azureDevOps}),bitbucket:new se({...t,...s==null?void 0:s.bitbucket}),bitbucketServer:new oe({...t,...s==null?void 0:s.bitbucketServer}),github:new ie({...t,...s==null?void 0:s.github}),gitlab:new ae({...t,...s==null?void 0:s.gitlab}),jira:new le({...t,...s==null?void 0:s.jira}),jiraServer:new pe({...t,...s==null?void 0:s.jiraServer}),trello:new de({...t,...s==null?void 0:s.trello})}},sn=rn;var nn={azureDevOps:Ne,bitbucket:_e,bitbucketServer:Be,github:et,gitlab:tt,gitProvider:Ze,jira:rt,trello:st,entityIdentifier:Ye};
|