@gitkraken/provider-apis 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +152 -152
- package/dist/providerUtils/azureDevops.d.ts +2 -2
- package/dist/providerUtils/bitbucket.d.ts +2 -2
- package/dist/providerUtils/bitbucketServer.d.ts +2 -2
- package/dist/providerUtils/entityIdentifiers/entityIdentifier.d.ts +5 -0
- package/dist/providerUtils/entityIdentifiers/providerEntityIdentifiers/azureDevopsIssueEntityIdentifier.d.ts +9 -0
- package/dist/providerUtils/entityIdentifiers/providerEntityIdentifiers/azureDevopsPullRequestEntityIdentifier.d.ts +9 -0
- package/dist/providerUtils/entityIdentifiers/providerEntityIdentifiers/bitbucketIssueEntityIdentifier.d.ts +9 -0
- package/dist/providerUtils/entityIdentifiers/providerEntityIdentifiers/bitbucketPullRequestEntityIdentifier.d.ts +9 -0
- package/dist/providerUtils/entityIdentifiers/providerEntityIdentifiers/githubIssueEntityIdentifier.d.ts +9 -0
- package/dist/providerUtils/entityIdentifiers/providerEntityIdentifiers/githubPullRequestEntityIdentifier.d.ts +9 -0
- package/dist/providerUtils/entityIdentifiers/providerEntityIdentifiers/gitlabIssueEntityIdentifier.d.ts +9 -0
- package/dist/providerUtils/entityIdentifiers/providerEntityIdentifiers/gitlabPullRequestEntityIdentifier.d.ts +9 -0
- package/dist/providerUtils/entityIdentifiers/providerEntityIdentifiers/jiraIssueEntityIdentifier.d.ts +9 -0
- package/dist/providerUtils/entityIdentifiers/providerEntityIdentifiers/trelloIssueEntityIdentifier.d.ts +9 -0
- package/dist/providerUtils/github.d.ts +0 -2
- package/dist/providerUtils/gitlab.d.ts +2 -2
- package/dist/providerUtils/jira.d.ts +2 -2
- package/dist/providerUtils/trello.d.ts +2 -1
- package/dist/types/exportedTypes/types.d.ts +37 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var rs=Object.create;var ne=Object.defineProperty;var ns=Object.getOwnPropertyDescriptor;var os=Object.getOwnPropertyNames;var as=Object.getPrototypeOf,is=Object.prototype.hasOwnProperty;var O=(r,s)=>{for(var e in s)ne(r,e,{get:s[e],enumerable:!0})},Pt=(r,s,e,t)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of os(s))!is.call(r,n)&&n!==e&&ne(r,n,{get:()=>s[n],enumerable:!(t=ns(s,n))||t.enumerable});return r};var us=(r,s,e)=>(e=r!=null?rs(as(r)):{},Pt(s||!r||!r.__esModule?ne(e,"default",{value:r,enumerable:!0}):e,r)),ls=r=>Pt(ne({},"__esModule",{value:!0}),r);var vr={};O(vr,{AzureDevOps:()=>K,AzureDevopsUtils:()=>Ee,Bitbucket:()=>V,BitbucketServer:()=>X,BitbucketServerUtils:()=>De,BitbucketUtils:()=>Ce,GitBuildStatusStage:()=>qt,GitBuildStatusState:()=>J,GitDiffLineType:()=>Oe,GitHub:()=>Y,GitHubIssueCloseReason:()=>ts,GitHubUtils:()=>Le,GitIssueState:()=>ue,GitLab:()=>Z,GitLabUtils:()=>$e,GitMergeStrategy:()=>H,GitProviderUtils:()=>Ue,GitPullRequestMergeableState:()=>x,GitPullRequestReviewState:()=>T,GitPullRequestState:()=>j,Jira:()=>te,JiraServer:()=>se,JiraUtils:()=>Ae,PullRequestAsyncStatus:()=>es,Trello:()=>re,TrelloUtils:()=>Ge,Utils:()=>Sr,default:()=>qr,isFetch:()=>oe});module.exports=ls(vr);var qt=(n=>(n.Build="build",n.Production="production",n.Staging="staging",n.Test="test",n))(qt||{}),J=(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))(J||{}),H=(o=>(o.MergeCommit="MERGE_COMMIT",o.Rebase="REBASE",o.RebaseThenMergeCommit="REBASE_THEN_MERGE_COMMIT",o.FastForward="FAST_FORWARD",o.Squash="SQUASH",o))(H||{}),j=(t=>(t.Open="OPEN",t.Closed="CLOSED",t.Merged="MERGED",t))(j||{}),T=(n=>(n.Approved="APPROVED",n.ChangesRequested="CHANGES_REQUESTED",n.Commented="COMMENTED",n.ReviewRequested="REVIEW_REQUESTED",n))(T||{}),x=(i=>(i.Behind="BEHIND",i.Blocked="BLOCKED",i.Conflicts="CONFLICTS",i.Mergeable="MERGEABLE",i.Unknown="UNKNOWN",i.UnknownAndBlocked="UNKNOWN_AND_BLOCKED",i.Unstable="UNSTABLE",i))(x||{}),Oe=(t=>(t.ADDED="ADDED",t.DELETED="DELETED",t.UNMODIFIED="UNMODIFIED",t))(Oe||{});var St={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},B=r=>!r||r.length===0?null:r.reduce((s,e)=>St[e.state]>St[s]?e.state:s,"APPROVED");var v=100;var vt=us(require("node-fetch")),Et=globalThis.fetch||vt.default;var ps=async r=>{let s=r.headers.get("content-type")||"",e=null;if(s.startsWith("application/json")){let n=await r.text();e=n.trim().length>0?JSON.parse(n):null}else if(s.startsWith("text/")||s==="")e=await r.text();else if(s.startsWith("application/vnd.github.raw+json"))e=await r.arrayBuffer();else throw new Error(`Unsupported content-type: ${s}`);let t={body:e,headers:Object.fromEntries(r.headers.entries()),status:r.status,statusText:r.statusText};if(!r.ok){let n=new Error(r.statusText);throw Object.assign(n,{response:t}),n}return t},Te=r=>async({url:s,...e})=>{let t=await r(s,e);return ps(t)};var oe=(r,s=!1)=>r.name==="fetch"||s;var U=class{constructor(s){let e=(s==null?void 0:s.request)||Et;this.config={...s,request:oe(e,s==null?void 0:s.forceIsFetch)?Te(e):e}}updateConfig(s){this.config={...this.config,...s,request:s.request&&oe(s.request,(s==null?void 0:s.forceIsFetch)??this.config.forceIsFetch)?Te(s.request):this.config.request}}},A=class extends U{};var f=(r,s)=>{let e={};return r&&(e.Authorization=`${s?"Basic":"Bearer"} ${r}`),e},Ct=r=>r?r.reduce((s,e)=>(s[e]=!0,s),{}):void 0,F=(r,s,e)=>!r||s.some(t=>r[t])?e:"";var q=(r,s={})=>f(s.token||r.token,s.isPAT||r.isPAT),Dt=r=>r.url.replace("/_apis/git/repositories/","/_git/").replace(`/${r.repository.project.id}/`,`/${encodeURIComponent(r.repository.project.name)}/`).replace(`/${r.repository.id}/`,`/${encodeURIComponent(r.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var Ut="https://app.vssps.visualstudio.com/_apis",S="https://dev.azure.com",ds={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},cs={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},xe=r=>({id:r.id,name:r.displayName,username:r.uniqueName||r.displayName,email:null,avatarUrl:r.imageUrl,url:null}),ie=r=>r.startsWith("refs/heads/")?r.replace("refs/heads/",""):r,ae=(r,s)=>{var t;let e=s.reviewers.filter(n=>n.vote!==0).map(n=>({reviewer:xe(n),state:cs[n.vote]||"REVIEW_REQUESTED"}));return{id:s.pullRequestId.toString(),title:s.title,number:s.codeReviewId,state:ds[s.status],isDraft:s.isDraft,commentCount:null,upvoteCount:null,author:xe(s.createdBy),createdDate:new Date(s.creationDate),updatedDate:new Date(s.closedDate||s.creationDate),closedDate:s.closedDate?new Date(s.closedDate):null,mergedDate:s.closedDate&&s.status==="completed"?new Date(s.closedDate):null,repository:{id:s.repository.id,name:s.repository.name,project:s.repository.project.name,owner:{login:r},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:ie(s.targetRefName),oid:s.lastMergeTargetCommit.commitId},headRef:{name:ie(s.sourceRefName),oid:s.lastMergeSourceCommit.commitId},url:Dt(s),assignees:s.reviewers.map(xe),reviews:e,reviewDecision:B(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((t=s.labels)==null?void 0:t.map(n=>({color:null,description:null,id:n.id,name:n.name})))??[],permissions:null}},Lt=(r,s)=>({id:s.id,name:s.name,namespace:r,project:s.project.name,webUrl:s.webUrl,httpsUrl:s.remoteUrl,sshUrl:s.sshUrl,defaultBranch:s.defaultBranch?{name:ie(s.defaultBranch)}:null,permission:null}),gs=(r,s,e,t)=>{var l,p;let n=e.fields,o=n["System.AssignedTo"],a=n["System.State"],i=n["System.WorkItemType"],u;return a&&i&&(u=(l=t[i])==null?void 0:l[a]),{id:e.id.toString(),number:e.id.toString(),title:n["System.Title"],commentCount:n["System.CommentCount"],author:{avatarUrl:n["System.CreatedBy"]._links.avatar.href,email:null,id:n["System.CreatedBy"].id,name:n["System.CreatedBy"].uniqueName,username:n["System.CreatedBy"].displayName,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:o._links.avatar.href,email:null,id:o.id,name:o.uniqueName,username:o.displayName,url:null}]:[],description:null,state:{name:(u==null?void 0:u.title)||a,color:null},type:n["System.WorkItemType"],repository:null,project:{namespace:r,name:s,resourceId:null},upvoteCount:0,labels:((p=e.fields["System.Tags"])==null?void 0:p.split(";").map(d=>({color:null,description:null,id:null,name:d.trim()})))??[]}},K=class extends U{async getCurrentUser(s={},e={}){if(e.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let t=await this.config.request({url:`${Ut}/profile/profiles/me`,headers:q(this.config,e)});return{data:{id:t.body.id,name:t.body.displayName,username:t.body.displayName,email:t.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(s,e={}){let n=(await this.config.request({url:`${S}/${encodeURIComponent(s.namespace)}/_apis/ConnectionData`,headers:q(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(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=(await this.config.request({url:`${S}/${encodeURIComponent(s.repo.namespace)}/${encodeURIComponent(s.repo.project)}/_apis/git/repositories/${encodeURIComponent(s.repo.name)}/commits/${s.oid}`,headers:q(this.config,e)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(s,e={}){return{data:(await this.config.request({url:`${Ut}/accounts?memberId=${s.userId}&api-version=6.0`,headers:q(this.config,e)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(s,e={}){let t=new URL(`${S}/${encodeURIComponent(s.namespace)}/_apis/projects`);t.searchParams.set("$top",v.toString()),s.cursor&&t.searchParams.set("$skip",s.cursor);let n=await this.config.request({url:t.toString(),headers:q(this.config,e)}),o=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:n.body.value.map(a=>({id:a.id,name:a.name,namespace:s.namespace}))}}async getAzureProjectScopeDescriptor(s,e={}){let{namespace:t,projectId:n}=s;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(t)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:q(this.config,e)})).body.value}}}async getAzureGraphAccountsForAzureProject(s,e={}){let{namespace:t,projectScopeDescriptor:n,cursor:o}=s,a=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(t)}/_apis/graph/users`);n&&a.searchParams.set("scopeDescriptor",n),o&&a.searchParams.set("continuationToken",o);let i=await this.config.request({url:a.toString(),headers:q(this.config,e)}),u=i.headers["x-ms-continuationtoken"];return{pageInfo:{endCursor:u||null,hasNextPage:!!u},data:i.body.value.map(l=>{var p;return{avatarUrl:((p=l._links.avatar)==null?void 0:p.href)??null,descriptor:l.descriptor,email:l.mailAddress,name:l.displayName,storageKeyURL:l._links.storageKey.href,username:l.displayName}})}}async getAccountFromAzureGraphAccount(s,e={}){let{azureGraphAccount:t}=s,n=await this.config.request({url:t.storageKeyURL,headers:q(this.config,e)});return{data:{avatarUrl:t.avatarUrl,email:t.email,id:n.body.value,name:t.name,username:t.username,url:null}}}async getAccountsFromAzureGraphAccounts(s,e={}){let t=[];for(let n of s.azureGraphAccounts){let o=await this.getAccountFromAzureGraphAccount({azureGraphAccount:n},e);t.push(o.data)}return{data:t}}async getRepo(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let t=await this.config.request({url:`${S}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories/${encodeURIComponent(s.name)}`,headers:q(this.config,e)});return{data:Lt(s.namespace,t.body)}}async getRepos(s,e={}){let t=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);t.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:t,errors:n}}async getReposForAzureProject(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${S}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories`,headers:q(this.config,e)})).body.value.map(n=>Lt(s.namespace,n))}}async getRefs(s,e,t={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${S}/${encodeURIComponent(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/refs`);n.searchParams.set("filter",s),n.searchParams.set("$top",v.toString()),e.cursor&&n.searchParams.set("continuationToken",e.cursor);let o=await this.config.request({url:n.toString(),headers:q(this.config,t)}),a=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:o.body.value.map(i=>({name:ie(i.name),commit:{oid:i.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(s,e={}){return this.getRefs("heads",s,e)}async getTags(s,e={}){return this.getRefs("tags",s,e)}async getPullRequestsForRepoBase(s,e={},t=100){let{page:n,repo:o,assigneeLogins:a,authorLogin:i}=s||{},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 a&&a.length&&(l+=`&searchCriteria.reviewerId=${a[0]}`),i&&(l+=`&searchCriteria.creatorId=${i}`),await this.config.request({url:`${e.baseUrl||S}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${t}&%24skip=${(u-1)*t}`,headers:q(this.config,e)})}async getPullRequestsForRepo(s,e={}){let n=s.page||1,o=await this.getPullRequestsForRepoBase(s,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(a=>ae(s.repo.namespace,a))}}async getPullRequestsForRepos(s,e={}){if(!s.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:t}=s||{},n=[];return await Promise.all(t.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...s},e)).body.value.forEach(i=>{n.push(ae(o.namespace,i))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:n}}async getPullRequestsForProjectBase(s,e={},t=100){let{namespace:n,project:o,page:a,assigneeLogins:i,authorLogin:u}=s,l=a||1,p=new URL(`${e.baseUrl||S}/${encodeURIComponent(n)}/${encodeURIComponent(o)}/_apis/git/pullRequests`);return p.searchParams.set("searchCriteria.status","1"),p.searchParams.set("$top",t.toString()),p.searchParams.set("$skip",((l-1)*t).toString()),i&&i.length&&p.searchParams.set("searchCriteria.reviewerId",i[0]),u&&p.searchParams.set("searchCriteria.creatorId",u),await this.config.request({url:p.toString(),headers:q(this.config,e)})}async getPullRequestsForProject(s,e={}){let n=s.page||1,o=await this.getPullRequestsForProjectBase(s,e,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(a=>ae(s.namespace,a))}}async getPullRequestsForProjects(s,e={}){let{projects:t}=s||{},n=[];return await Promise.all(t.map(async o=>{try{(await this.getPullRequestsForProjectBase({...o,...s},e)).body.value.forEach(i=>{n.push(ae(o.namespace,i))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:n}}async getAzurePullRequestLastMergeStatus(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:{namespace:t,project:n,name:o},pullRequestId:a}=s,i=await this.config.request({url:`${e.baseUrl||S}/${encodeURIComponent(t)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}?includeCommits=true?api-version=6.0`,headers:{...q(this.config,e)}});if(!i.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:i.body.mergeStatus}}async updatePullRequest(s,e,t){return await this.config.request({method:"PATCH",url:`${t.baseUrl||S}/${encodeURIComponent(s.repository.owner.login)}/${encodeURIComponent(s.repository.project)}/_apis/git/repositories/${s.repository.name}/pullrequests/${s.id}?api-version=6.0`,body:e,headers:{...q(this.config,t),"Content-Type":"application/json"}})}async closePullRequest(s,e={}){let{pullRequest:t}=s,n={status:"abandoned"};if(!(await this.updatePullRequest(t,JSON.stringify(n),e)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){var u;let{pullRequest:t,mergeStrategy:n}=s,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 a={completionOptions:{mergeStrategy:o},lastMergeSourceCommit:{commitId:(u=t.headRef)==null?void 0:u.oid},status:"completed"};if(!(await this.updatePullRequest(t,JSON.stringify(a),e)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(s,e={}){let{pullRequest:t,label:n}=s;if(!t.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||S}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/labels?api-version=6.0`,body:JSON.stringify(o),headers:{...q(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(s,e={}){let{pullRequest:t,label:n}=s;if(!t.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||S}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/labels/${encodeURIComponent(n.name)}?api-version=6.0`,headers:{...q(this.config,e)}})}async setPullRequestLabels(s,e={}){let{pullRequest:t,labels:n}=s;if(!t.repository.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let o=t.labels;if(!o)throw new Error('Azure DevOps requires "labels" for this function.');for(let a of n)o.find(i=>i.id===a.id)||await this.addPullRequestLabel({pullRequest:t,label:a},e);for(let a of o)n.find(i=>a.id===i.id)||await this.removePullRequestLabel({pullRequest:t,label:a},e)}async setPullRequestAsDraft(s,e={}){let{pullRequest:t,isDraft:n}=s,o={isDraft:n};if(!(await this.updatePullRequest(t,JSON.stringify(o),e)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(s,e={}){let{pullRequest:t,reviewer:n,isRequired:o}=s,a={id:n.id,isRequired:o};if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||S}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/reviewers/${n.id}?api-version=6.0`,body:JSON.stringify(a),headers:{...q(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(s,e={}){let{pullRequest:t,reviewer:n}=s;await this.config.request({method:"DELETE",url:`${e.baseUrl||S}/${encodeURIComponent(t.repository.owner.login)}/${encodeURIComponent(t.repository.project)}/_apis/git/repositories/${t.repository.name}/pullrequests/${t.id}/reviewers/${n.id}?api-version=6.0`,headers:{...q(this.config,e),Accept:"application/json"}})}async setPullRequestReviewers(s,e={}){let{pullRequest:t,reviewers:n}=s;for(let o of n)t.assignees.find(a=>a.id===o.id)||await this.addPullRequestReviewer({pullRequest:t,reviewer:o,isRequired:!0},e);for(let o of t.assignees)n.find(a=>o.id===a.id)||await this.removePullRequestReviewer({pullRequest:t,reviewer:o},e)}async getIssuesForAzureProject(s,e={}){let{page:t,assigneeLogins:n,authorLogin:o,mentionLogin:a,statusByWorkItemIdByStatusId:i}=s||{},u=t||1,l=200,p=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&p.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),n&&n[0]&&p.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),a&&p.push("[System.Id] IN (@recentMentions)");let d=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${p.join(" AND ")} order by [System.CreatedDate] desc`,c=await this.config.request({url:`${e.baseUrl||S}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:d}),method:"POST",headers:{...q(this.config,e),"Content-Type":"application/json"}}),g=c.body.workItems.slice((u-1)*l,l*u).map(R=>R.id);if(g.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let m=await this.config.request({url:`${e.baseUrl||S}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:g,$expand:"Links"}),method:"POST",headers:{...q(this.config,e),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:c.body.workItems.length>l*u,nextPage:u+1},data:m.body.value.map(R=>gs(s.namespace,s.project,R,i||{}))}}async updateIssue(s,e,t={}){return await this.config.request({method:"PATCH",url:`${t.baseUrl||S}/${encodeURIComponent(s.project.namespace)}/${encodeURIComponent(s.project.name)}/_apis/wit/workitems/${s.id}?api-version=6.0`,body:JSON.stringify(e),headers:{...q(this.config,t),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(s,e={}){var i;let{issue:t,status:n}=s,o=[{op:"add",path:"/fields/System.State",value:n.name}];if(!((i=(await this.updateIssue(t,o,e)).body.fields)!=null&&i["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(s,e={}){var i;let{issue:t,assignee:n}=s,o=[{op:"add",path:"/fields/System.AssignedTo",value:(n==null?void 0:n.name)??""}];if(!((i=(await this.updateIssue(t,o,e)).body.fields)!=null&&i["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(s,e={}){var u;let{issue:t,labels:n}=s,a=[{op:"replace",path:"/fields/System.Tags",value:n.map(l=>l.name).join(";")}];if(!((u=(await this.updateIssue(t,a,e)).body.fields)!=null&&u["System.Tags"]))throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:t,project:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||S}/${encodeURIComponent(t)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...q(this.config,e)}})).body.value}}async getLabelsForProject(s,e={}){let{namespace:t,project:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||S}/${encodeURIComponent(t)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...q(this.config,e)}})).body.value.map(a=>({color:null,description:null,id:a.id,name:a.name,url:a.url}))}}};var E=(r,s={})=>f(s.token||r.token,s.isPAT||r.isPAT);var L="https://api.bitbucket.org/2.0",ms={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},At=r=>({id:r.uuid,name:r.display_name||r.nickname,username:r.nickname||r.display_name,email:null,avatarUrl:r.links.avatar.href,url:r.links.html.href}),$t=r=>{var s,e;return{id:r.uuid,namespace:r.workspace.slug,name:r.slug,webUrl:r.links.html.href,httpsUrl:((s=r.links.clone.find(t=>t.name==="https"))==null?void 0:s.href)??null,sshUrl:((e=r.links.clone.find(t=>t.name==="ssh"))==null?void 0:e.href)??null,defaultBranch:{name:r.mainbranch.name},permission:null}},ke=r=>{let s=r.id;return{id:s.toString(),title:r.title,number:s,state:ms[r.state],isDraft:!1,commentCount:r.comment_count,upvoteCount:null,author:At(r.author),createdDate:new Date(r.created_on),updatedDate:new Date(r.updated_on),closedDate:null,mergedDate:null,repository:{id:r.destination.repository.uuid,name:r.destination.repository.name,owner:{login:r.destination.repository.full_name.split("/")[0]},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:r.destination.branch.name,oid:r.destination.commit.hash},headRef:{name:r.source.branch.name,oid:r.source.commit.hash},url:r.links.html.href,assignees:null,reviews:null,reviewDecision:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",permissions:null}},V=class extends U{async refreshToken(s){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 ${s.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${s.refreshToken}`})).body}}async getCurrentUser(s={},e={}){let t=await this.config.request({url:`${L}/user`,headers:E(this.config,e)});return{data:At(t.body)}}async getUserForCommit(s,e={}){var a;let n=(await this.config.request({url:`${L}/repositories/${s.repo.namespace}/${s.repo.name}/commit/${s.oid}`,headers:E(this.config,e)})).body.author,o=n.raw.match(/([^<]+)<(.+)>/);return{data:{name:o?o[1].trim():null,email:o?o[2]:null,avatarUrl:((a=n.user)==null?void 0:a.links.avatar.href)||null}}}async getRepo(s,e={}){let t=await this.config.request({url:`${L}/repositories/${s.namespace}/${s.name}`,headers:E(this.config,e)});return{data:$t(t.body)}}async getRepos(s,e={}){let t=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);t.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:t,errors:n}}async getReposForCurrentUser(s,e={}){let t=new URL(`${L}/repositories`);t.searchParams.set("role","member"),t.searchParams.set("pagelen",v.toString()),s.cursor&&t.searchParams.set("after",s.cursor);let n=await this.config.request({url:t.toString(),headers:E(this.config,e)}),o=!!n.body.next,a=null;return n.body.next&&(a=new URL(n.body.next).searchParams.get("after")),{pageInfo:{hasNextPage:o,endCursor:a},data:n.body.values.map($t)}}async getBranches(s,e={}){var a;let t=new URL(`${L}/repositories/${s.repo.namespace}/${s.repo.name}/refs/branches`);t.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),t.searchParams.set("pagelen",v.toString());let n=await this.config.request({url:t.toString(),headers:E(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getTags(s,e={}){let t=new URL(`${L}/repositories/${s.repo.namespace}/${s.repo.name}/refs/tags`);t.searchParams.set("pagelen",v.toString()),s.cursor&&t.searchParams.set("page",s.cursor);let n=await this.config.request({url:t.toString(),headers:E(this.config,e)}),o=!!n.body.next,a=null;return n.body.next&&(a=new URL(n.body.next).searchParams.get("page")),{pageInfo:{hasNextPage:o,endCursor:a},data:n.body.values.map(i=>{let u=new Date(i.target.date);return{name:i.name,commit:{oid:i.target.hash,authoredDate:u,committedDate:u}}})}}async getPullRequestsForUser(s,e={}){var a;let t=new URL(`${L}/pullrequests/${s.userId}`);t.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),t.searchParams.set("pagelen","50");let n=await this.config.request({url:t.toString(),headers:E(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(ke)}}async getPullRequestsForRepoBase(s,e={}){var n;let t=new URL(`${L}/repositories/${encodeURI(s.repo.namespace)}/${encodeURI(s.repo.name)}/pullrequests?state=OPEN`);return t.searchParams.set("page",((n=s.page)==null?void 0:n.toString())||"1"),t.searchParams.set("pagelen","50"),await this.config.request({url:t.toString(),headers:E(this.config,e)})}async getPullRequestsForRepo(s,e={}){let t=[],n=await this.getPullRequestsForRepoBase(s,e);n.body.values.forEach(a=>{if(s.authorLogin&&a.author.uuid!==s.authorLogin)return null;t.push(ke(a))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:t}}async getPullRequestsForRepos(s,e={}){let t=[];return await Promise.all(s.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...s},e)).body.values.forEach(a=>{if(s.authorLogin&&a.author.uuid!==s.authorLogin)return null;t.push(ke(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:t}}async closePullRequest(s,e={}){let{pullRequest:t}=s;if(!(await this.config.request({method:"POST",url:`${L}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}/decline`,headers:E(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){let{pullRequest:t,mergeStrategy:n}=s,o;switch(n){case"MERGE_COMMIT":{o="merge_commit";break}case"FAST_FORWARD":{o="fast_forward";break}case"SQUASH":{o="squash";break}}let a={merge_strategy:o,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${L}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}/merge`,body:JSON.stringify(a),headers:{...E(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(s,e={}){let{pullRequest:t,reviewers:n}=s,o={reviewers:n.map(i=>{if(i.username)throw new Error('Bitbucket reviewer requires "username" for this function.');return{username:i.username}})};if(!(await this.config.request({method:"PUT",url:`${L}/repositories/${t.repository.owner.login}/${t.repository.name}/pullrequests/${t.id}`,body:JSON.stringify(o),headers:{...E(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var Ne=r=>({name:r.displayName,email:r.emailAddress,avatarUrl:r.avatarUrl??null,id:r.id.toString(),username:r.name,url:r.links.self[0].href}),_e=r=>{var u,l,p,d,c,g;let s={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},e={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},t=r.reviewers.map(m=>({reviewer:Ne(m.user),state:e[m.status]})),n=((u=r.toRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:u.href)??null,o=((l=r.toRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:l.href)??null;o||(o=((p=r.toRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:p.href)??null);let a=((d=r.fromRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:d.href)??null,i=((c=r.fromRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:c.href)??null;return i||(i=((g=r.fromRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:g.href)??null),{id:r.id.toString(),number:r.id,title:r.title,url:r.links.self[0].href,state:s[r.state],isDraft:!1,createdDate:new Date(r.createdDate),updatedDate:new Date(r.updatedDate),closedDate:r.closedDate?new Date(r.closedDate):null,mergedDate:r.state=="MERGED"&&r.closedDate?new Date(r.closedDate):null,baseRef:{name:r.toRef.displayId,oid:r.toRef.latestCommit},headRef:{name:r.fromRef.displayId,oid:r.fromRef.latestCommit},commentCount:r.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:Ne(r.author.user),assignees:null,reviews:t,reviewDecision:B(t),repository:{id:r.toRef.repository.id.toString(),name:r.toRef.repository.name,owner:{login:r.toRef.repository.project.key},remoteInfo:o&&n?{cloneUrlHTTPS:o,cloneUrlSSH:n}:null},headRepository:{id:r.fromRef.repository.id.toString(),name:r.fromRef.repository.name,owner:{login:r.fromRef.repository.project.key},remoteInfo:i&&a?{cloneUrlHTTPS:i,cloneUrlSSH:a}:null},headCommit:null,mergeableState:"UNKNOWN",permissions:null,version:r.version}},Gt=r=>{var s,e,t;return{id:r.id.toString(),namespace:r.project.key,name:r.slug,webUrl:((s=r.links.self[0])==null?void 0:s.href)??null,httpsUrl:((e=r.links.clone.find(n=>n.name==="https"))==null?void 0:e.href)??null,sshUrl:((t=r.links.clone.find(n=>n.name==="ssh"))==null?void 0:t.href)??null,defaultBranch:null,permission:null}},X=class extends A{getBaseUrl(s){let e=s.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(s){return f(s.token||this.config.token)}async getCurrentUser(s={},e={}){let t=await this.config.request({url:`${this.getBaseUrl(e)}/users?limit=2`,headers:this.getRequestHeaders(e)}),{headers:{"x-auserid":n,"x-ausername":o}}=t,a=n?parseInt(n,10):null,i=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})=>a?a===d:i===c||i===p||i===g);if(!l)throw new Error("Could not find current Bitbucket Server user");return{data:Ne(l)}}async getRepo(s,e={}){let t=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${s.namespace}/repos/${s.name}`,headers:this.getRequestHeaders(e)});return{data:Gt(t.body)}}async getRepos(s,e={}){let t=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);t.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:t,errors:n}}async getReposForCurrentUser(s,e={}){let t=s.page??0,n=await this.config.request({url:`${this.getBaseUrl(e)}/repos?start=${t}`,headers:this.getRequestHeaders(e)});return{pageInfo:{hasNextPage:!n.body.isLastPage,nextPage:n.body.nextPageStart},data:n.body.values.map(Gt)}}async getPullRequestsForRepoBase(s,e={}){var n;let t=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(s.repo.namespace)}/repos/${encodeURI(s.repo.name)}/pull-requests?state=OPEN`);return t.searchParams.set("start",((n=s.page)==null?void 0:n.toString())||"0"),t.searchParams.set("limit","50"),await this.config.request({url:t.toString(),headers:this.getRequestHeaders(e)})}async getPullRequestsForRepo(s,e={}){let t=[],n=await this.getPullRequestsForRepoBase(s,e);n.body.values.forEach(a=>{if(s.authorLogin&&a.author.user.name!==s.authorLogin)return null;t.push(_e(a))});let o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:t}}async getPullRequestsForRepos(s,e={}){let t=[];return await Promise.all(s.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...s},e)).body.values.forEach(a=>{if(s.authorLogin&&a.author.user.name!==s.authorLogin)return null;t.push(_e(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:t}}async getPullRequestsForCurrentUser(s,e={}){var a;let t=new URL(`${this.getBaseUrl(e)}/dashboard/pull-requests`);t.searchParams.set("state","OPEN"),t.searchParams.set("start",((a=s.page)==null?void 0:a.toString())||"0"),t.searchParams.set("limit","50");let n=await this.config.request({url:t.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(_e)}}async closePullRequest(s,e={}){let{pullRequest:t}=s;if(t.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/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}/decline`,body:JSON.stringify({version:t.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){let{pullRequest:t,mergeStrategyId:n}=s;if(s.mergeStrategy)throw new Error('Bitbucket Server uses "mergeStrategyId" instead of "mergeStrategy".');if(t.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/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.id}/merge`,body:JSON.stringify({strategyId:n,version:t.version}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(s={}){let e=await this.config.request({url:`${this.getBaseUrl(s)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(s),"Content-Type":"application/json"}});return{data:{defaultStrategy:e.body.mergeConfig.defaultStrategy,strategies:e.body.mergeConfig.strategies}}}async setPullRequestReviewers(s,e={}){let{pullRequest:t,reviewers:n}=s;if(t.version===void 0)throw new Error('Bitbucket Server requires "version" for this function.');let o={reviewers:n.map(i=>{if(i.username)throw new Error('Bitbucket Server reviewer requires "username" for this function.');return{user:{name:i.username}}}),version:t.version};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${t.repository.owner.login}/repos/${t.repository.name}/pull-requests/${t.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 kt=require("js-base64");var ue=(e=>(e.Open="OPEN",e.Closed="CLOSED",e))(ue||{});var hs={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0]},le=(r,s)=>{let e=hs[s];for(let t=0;t<3;t++){if(r[t]>e[t])return!0;if(r[t]<e[t])return!1}return!0},de="https://api.github.com",fs=`${de}/graphql`,ce=`
|
|
1
|
+
"use strict";var Rr=Object.create;var ae=Object.defineProperty;var yr=Object.getOwnPropertyDescriptor;var br=Object.getOwnPropertyNames;var wr=Object.getPrototypeOf,Pr=Object.prototype.hasOwnProperty;var T=(s,e)=>{for(var t in e)ae(s,t,{get:e[t],enumerable:!0})},xt=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of br(e))!Pr.call(s,n)&&n!==t&&ae(s,n,{get:()=>e[n],enumerable:!(r=yr(e,n))||r.enumerable});return s};var Er=(s,e,t)=>(t=s!=null?Rr(wr(s)):{},xt(e||!s||!s.__esModule?ae(t,"default",{value:s,enumerable:!0}):t,s)),qr=s=>xt(ae({},"__esModule",{value:!0}),s);var _s={};T(_s,{AzureDevOps:()=>Y,AzureDevopsUtils:()=>Le,Bitbucket:()=>Z,BitbucketServer:()=>ee,BitbucketServerUtils:()=>$e,BitbucketUtils:()=>Ue,EntityIdentifier:()=>Me,EntityIdentifierProviderType:()=>D,EntityType:()=>C,EntityVersion:()=>S,GitBuildStatusStage:()=>_t,GitBuildStatusState:()=>X,GitDiffLineType:()=>Ve,GitHub:()=>te,GitHubIssueCloseReason:()=>fr,GitHubUtils:()=>ze,GitIssueState:()=>de,GitLab:()=>re,GitLabUtils:()=>He,GitMergeStrategy:()=>V,GitProviderUtils:()=>Fe,GitPullRequestMergeableState:()=>N,GitPullRequestReviewState:()=>_,GitPullRequestState:()=>H,Jira:()=>ne,JiraServer:()=>oe,JiraUtils:()=>We,PullRequestAsyncStatus:()=>hr,Trello:()=>ie,TrelloUtils:()=>Je,Utils:()=>xs,default:()=>ks,isFetch:()=>ue});module.exports=qr(_s);var _t=(n=>(n.Build="build",n.Production="production",n.Staging="staging",n.Test="test",n))(_t||{}),X=(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))(X||{}),V=(o=>(o.MergeCommit="MERGE_COMMIT",o.Rebase="REBASE",o.RebaseThenMergeCommit="REBASE_THEN_MERGE_COMMIT",o.FastForward="FAST_FORWARD",o.Squash="SQUASH",o))(V||{}),H=(r=>(r.Open="OPEN",r.Closed="CLOSED",r.Merged="MERGED",r))(H||{}),_=(n=>(n.Approved="APPROVED",n.ChangesRequested="CHANGES_REQUESTED",n.Commented="COMMENTED",n.ReviewRequested="REVIEW_REQUESTED",n))(_||{}),N=(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))(N||{}),Ve=(r=>(r.ADDED="ADDED",r.DELETED="DELETED",r.UNMODIFIED="UNMODIFIED",r))(Ve||{});var Nt={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},F=s=>!s||s.length===0?null:s.reduce((e,t)=>Nt[t.state]>Nt[e]?t.state:e,"APPROVED");var v=100;var Qt=Er(require("node-fetch")),Bt=globalThis.fetch||Qt.default;var vr=async s=>{let e=s.headers.get("content-type")||"",t=null;if(e.startsWith("application/json")){let n=await s.text();t=n.trim().length>0?JSON.parse(n):null}else if(e.startsWith("text/")||e==="")t=await s.text();else if(e.startsWith("application/vnd.github.raw+json"))t=await s.arrayBuffer();else throw new Error(`Unsupported content-type: ${e}`);let r={body:t,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},Ke=s=>async({url:e,...t})=>{let r=await s(e,t);return vr(r)};var ue=(s,e=!1)=>s.name==="fetch"||e,S=(t=>(t.Zero="0",t.One="1",t))(S||{}),C=(t=>(t.PullRequest="0",t.Issue="1",t))(C||{}),D=(p=>(p.Azure="0",p.Github="1",p.GithubEnterprise="2",p.Gitlab="3",p.GitlabSelfHosted="4",p.Bitbucket="5",p.BitbucketServer="6",p.Jira="7",p.JiraServer="8",p.Trello="9",p))(D||{});var A=class{constructor(e){let t=(e==null?void 0:e.request)||Bt;this.config={...e,request:ue(t,e==null?void 0:e.forceIsFetch)?Ke(t):t}}updateConfig(e){this.config={...this.config,...e,request:e.request&&ue(e.request,(e==null?void 0:e.forceIsFetch)??this.config.forceIsFetch)?Ke(e.request):this.config.request}}},k=class extends A{};var f=(s,e)=>{let t={};return s&&(t.Authorization=`${e?"Basic":"Bearer"} ${s}`),t},jt=s=>s?s.reduce((e,t)=>(e[t]=!0,e),{}):void 0,z=(s,e,t)=>!s||e.some(r=>s[r])?t:"";var E=(s,e={})=>f(e.token||s.token,e.isPAT||s.isPAT),Mt=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 Ft="https://app.vssps.visualstudio.com/_apis",q="https://dev.azure.com",Sr={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Cr={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},Xe=s=>({id:s.id,name:s.displayName,username:s.uniqueName||s.displayName,email:null,avatarUrl:s.imageUrl,url:null}),pe=s=>s.startsWith("refs/heads/")?s.replace("refs/heads/",""):s,le=(s,e)=>{var r;let t=e.reviewers.filter(n=>n.vote!==0).map(n=>({reviewer:Xe(n),state:Cr[n.vote]||"REVIEW_REQUESTED"}));return{id:e.pullRequestId.toString(),title:e.title,number:e.codeReviewId,state:Sr[e.status],isDraft:e.isDraft,commentCount:null,upvoteCount:null,author:Xe(e.createdBy),createdDate:new Date(e.creationDate),updatedDate:new Date(e.closedDate||e.creationDate),closedDate:e.closedDate?new Date(e.closedDate):null,mergedDate:e.closedDate&&e.status==="completed"?new Date(e.closedDate):null,repository:{id:e.repository.id,name:e.repository.name,project:e.repository.project.name,owner:{login:s},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:pe(e.targetRefName),oid:e.lastMergeTargetCommit.commitId},headRef:{name:pe(e.sourceRefName),oid:e.lastMergeSourceCommit.commitId},url:Mt(e),assignees:e.reviewers.map(Xe),reviews:t,reviewDecision:F(t),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((r=e.labels)==null?void 0:r.map(n=>({color:null,description:null,id:n.id,name:n.name})))??[],permissions:null}},zt=(s,e)=>({id:e.id,name:e.name,namespace:s,project:e.project.name,webUrl:e.webUrl,httpsUrl:e.remoteUrl,sshUrl:e.sshUrl,defaultBranch:e.defaultBranch?{name:pe(e.defaultBranch)}:null,permission:null}),Dr=(s,e,t,r)=>{var l,p;let n=t.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:t.id.toString(),number:t.id.toString(),title:n["System.Title"],commentCount:n["System.CommentCount"],author:{avatarUrl:n["System.CreatedBy"]._links.avatar.href,email:null,id:n["System.CreatedBy"].id,name:n["System.CreatedBy"].uniqueName,username:n["System.CreatedBy"].displayName,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:t._links.html.href,assignees:o?[{avatarUrl:o._links.avatar.href,email:null,id:o.id,name:o.uniqueName,username:o.displayName,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:e,resourceId:null},upvoteCount:0,labels:((p=t.fields["System.Tags"])==null?void 0:p.split(";").map(d=>({color:null,description:null,id:null,name:d.trim()})))??[]}},Y=class extends A{async getCurrentUser(e={},t={}){if(t.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let r=await this.config.request({url:`${Ft}/profile/profiles/me`,headers:E(this.config,t)});return{data:{id:r.body.id,name:r.body.displayName,username:r.body.displayName,email:r.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(e,t={}){let n=(await this.config.request({url:`${q}/${encodeURIComponent(e.namespace)}/_apis/ConnectionData`,headers:E(this.config,t)})).body.authorizedUser;if(n.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:n.id,name:n.providerDisplayName,username:n.providerDisplayName,email:n.properties.Account.$value,avatarUrl:null}}}async getUserForCommit(e,t={}){if(!e.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(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/commits/${e.oid}`,headers:E(this.config,t)})).body.author;return{data:{name:n.name,email:n.email,avatarUrl:n.imageUrl}}}async getOrgsForUser(e,t={}){return{data:(await this.config.request({url:`${Ft}/accounts?memberId=${e.userId}&api-version=6.0`,headers:E(this.config,t)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(e,t={}){let r=new URL(`${q}/${encodeURIComponent(e.namespace)}/_apis/projects`);r.searchParams.set("$top",v.toString()),e.cursor&&r.searchParams.set("$skip",e.cursor);let n=await this.config.request({url:r.toString(),headers:E(this.config,t)}),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:e.namespace}))}}async getAzureProjectScopeDescriptor(e,t={}){let{namespace:r,projectId:n}=e;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:E(this.config,t)})).body.value}}}async getAzureGraphAccountsForAzureProject(e,t={}){let{namespace:r,projectScopeDescriptor:n,cursor:o}=e,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:E(this.config,t)}),u=a.headers["x-ms-continuationtoken"];return{pageInfo:{endCursor:u||null,hasNextPage:!!u},data:a.body.value.map(l=>{var p;return{avatarUrl:((p=l._links.avatar)==null?void 0:p.href)??null,descriptor:l.descriptor,email:l.mailAddress,name:l.displayName,storageKeyURL:l._links.storageKey.href,username:l.displayName}})}}async getAccountFromAzureGraphAccount(e,t={}){let{azureGraphAccount:r}=e,n=await this.config.request({url:r.storageKeyURL,headers:E(this.config,t)});return{data:{avatarUrl:r.avatarUrl,email:r.email,id:n.body.value,name:r.name,username:r.username,url:null}}}async getAccountsFromAzureGraphAccounts(e,t={}){let r=[];for(let n of e.azureGraphAccounts){let o=await this.getAccountFromAzureGraphAccount({azureGraphAccount:n},t);r.push(o.data)}return{data:r}}async getRepo(e,t={}){if(!e.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=await this.config.request({url:`${q}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/git/repositories/${encodeURIComponent(e.name)}`,headers:E(this.config,t)});return{data:zt(e.namespace,r.body)}}async getRepos(e,t={}){let r=[],n=[];return await Promise.all(e.map(async o=>{try{let i=await this.getRepo(o,t);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForAzureProject(e,t={}){if(!e.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');return{data:(await this.config.request({url:`${q}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/git/repositories`,headers:E(this.config,t)})).body.value.map(n=>zt(e.namespace,n))}}async getRefs(e,t,r={}){if(!t.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${q}/${encodeURIComponent(t.repo.namespace)}/${encodeURIComponent(t.repo.project)}/_apis/git/repositories/${encodeURIComponent(t.repo.name)}/refs`);n.searchParams.set("filter",e),n.searchParams.set("$top",v.toString()),t.cursor&&n.searchParams.set("continuationToken",t.cursor);let o=await this.config.request({url:n.toString(),headers:E(this.config,r)}),i=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!i,endCursor:i||null},data:o.body.value.map(a=>({name:pe(a.name),commit:{oid:a.objectId,authoredDate:null,committedDate:null}}))}}async getBranches(e,t={}){return this.getRefs("heads",e,t)}async getTags(e,t={}){return this.getRefs("tags",e,t)}async getPullRequestsForRepoBase(e,t={},r=100){let{page:n,repo:o,assigneeLogins:i,authorLogin:a}=e||{},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:`${t.baseUrl||q}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${r}&%24skip=${(u-1)*r}`,headers:E(this.config,t)})}async getPullRequestsForRepo(e,t={}){let n=e.page||1,o=await this.getPullRequestsForRepoBase(e,t,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(i=>le(e.repo.namespace,i))}}async getPullRequestsForRepos(e,t={}){if(!e.repos.every(o=>o.project))throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repos:r}=e||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...e},t)).body.value.forEach(a=>{n.push(le(o.namespace,a))})}catch(i){if(i.statusCode!==404&&i.statusCode!==401)throw i}})),{data:n}}async getPullRequestsForProjectBase(e,t={},r=100){let{namespace:n,project:o,page:i,assigneeLogins:a,authorLogin:u}=e,l=i||1,p=new URL(`${t.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:E(this.config,t)})}async getPullRequestsForProject(e,t={}){let n=e.page||1,o=await this.getPullRequestsForProjectBase(e,t,100);return{pageInfo:{hasNextPage:o.body.value.length===100,nextPage:n+1},data:o.body.value.map(i=>le(e.namespace,i))}}async getPullRequestsForProjects(e,t={}){let{projects:r}=e||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForProjectBase({...o,...e},t)).body.value.forEach(a=>{n.push(le(o.namespace,a))})}catch(i){if(i.statusCode!==404&&i.statusCode!==401)throw i}})),{data:n}}async getAzurePullRequestLastMergeStatus(e,t={}){if(!e.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}=e,a=await this.config.request({url:`${t.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${i}?includeCommits=true?api-version=6.0`,headers:{...E(this.config,t)}});if(!a.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:a.body.mergeStatus}}async updatePullRequest(e,t,r){return await this.config.request({method:"PATCH",url:`${r.baseUrl||q}/${encodeURIComponent(e.repository.owner.login)}/${encodeURIComponent(e.repository.project)}/_apis/git/repositories/${e.repository.name}/pullrequests/${e.id}?api-version=6.0`,body:t,headers:{...E(this.config,r),"Content-Type":"application/json"}})}async closePullRequest(e,t={}){let{pullRequest:r}=e,n={status:"abandoned"};if(!(await this.updatePullRequest(r,JSON.stringify(n),t)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(e,t={}){var u;let{pullRequest:r,mergeStrategy:n}=e,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),t)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(e,t={}){let{pullRequest:r,label:n}=e;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:`${t.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:{...E(this.config,t),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(e,t={}){let{pullRequest:r,label:n}=e;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:`${t.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:{...E(this.config,t)}})}async setPullRequestLabels(e,t={}){let{pullRequest:r,labels:n}=e;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},t);for(let i of o)n.find(a=>i.id===a.id)||await this.removePullRequestLabel({pullRequest:r,label:i},t)}async setPullRequestAsDraft(e,t={}){let{pullRequest:r,isDraft:n}=e,o={isDraft:n};if(!(await this.updatePullRequest(r,JSON.stringify(o),t)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(e,t={}){let{pullRequest:r,reviewer:n,isRequired:o}=e,i={id:n.id,isRequired:o};if(!(await this.config.request({method:"PUT",url:`${t.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:{...E(this.config,t),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(e,t={}){let{pullRequest:r,reviewer:n}=e;await this.config.request({method:"DELETE",url:`${t.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:{...E(this.config,t),Accept:"application/json"}})}async setPullRequestReviewers(e,t={}){let{pullRequest:r,reviewers:n}=e;for(let o of n)r.assignees.find(i=>i.id===o.id)||await this.addPullRequestReviewer({pullRequest:r,reviewer:o,isRequired:!0},t);for(let o of r.assignees)n.find(i=>o.id===i.id)||await this.removePullRequestReviewer({pullRequest:r,reviewer:o},t)}async getIssuesForAzureProject(e,t={}){let{page:r,assigneeLogins:n,authorLogin:o,mentionLogin:i,statusByWorkItemIdByStatusId:a}=e||{},u=r||1,l=200,p=["[Microsoft.VSTS.Common.ClosedDate] = ''","[System.TeamProject] = @project","[Microsoft.VSTS.Common.ResolvedDate] = ''"];o&&p.push(`[System.CreatedBy] = '${o.replace("'","''")}'`),n&&n[0]&&p.push(`[System.AssignedTo] = '${n[0].replace("'","''")}'`),i&&p.push("[System.Id] IN (@recentMentions)");let d=`Select [Microsoft.VSTS.Common.ClosedDate], [Microsoft.VSTS.Common.ResolvedDate] From WorkItems Where ${p.join(" AND ")} order by [System.CreatedDate] desc`,c=await this.config.request({url:`${t.baseUrl||q}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:d}),method:"POST",headers:{...E(this.config,t),"Content-Type":"application/json"}}),g=c.body.workItems.slice((u-1)*l,l*u).map(I=>I.id);if(g.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let m=await this.config.request({url:`${t.baseUrl||q}/${encodeURIComponent(e.namespace)}/${encodeURIComponent(e.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:g,$expand:"Links"}),method:"POST",headers:{...E(this.config,t),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:c.body.workItems.length>l*u,nextPage:u+1},data:m.body.value.map(I=>Dr(e.namespace,e.project,I,a||{}))}}async updateIssue(e,t,r={}){return await this.config.request({method:"PATCH",url:`${r.baseUrl||q}/${encodeURIComponent(e.project.namespace)}/${encodeURIComponent(e.project.name)}/_apis/wit/workitems/${e.id}?api-version=6.0`,body:JSON.stringify(t),headers:{...E(this.config,r),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(e,t={}){var a;let{issue:r,status:n}=e,o=[{op:"add",path:"/fields/System.State",value:n.name}];if(!((a=(await this.updateIssue(r,o,t)).body.fields)!=null&&a["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(e,t={}){var a;let{issue:r,assignee:n}=e,o=[{op:"add",path:"/fields/System.AssignedTo",value:(n==null?void 0:n.name)??""}];if(!((a=(await this.updateIssue(r,o,t)).body.fields)!=null&&a["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(e,t={}){var u;let{issue:r,labels:n}=e,i=[{op:"replace",path:"/fields/System.Tags",value:n.map(l=>l.name).join(";")}];if(!((u=(await this.updateIssue(r,i,t)).body.fields)!=null&&u["System.Tags"]))throw new Error("Could not set issue tags")}async getIssueTypesForAzureProject(e,t={}){if(!e.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...E(this.config,t)}})).body.value}}async getLabelsForProject(e,t={}){let{namespace:r,project:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...E(this.config,t)}})).body.value.map(i=>({color:null,description:null,id:i.id,name:i.name,url:i.url}))}}};var L=(s,e={})=>f(e.token||s.token,e.isPAT||s.isPAT);var G="https://api.bitbucket.org/2.0",Lr={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},Wt=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}),Ht=s=>{var e,t;return{id:s.uuid,namespace:s.workspace.slug,name:s.slug,webUrl:s.links.html.href,httpsUrl:((e=s.links.clone.find(r=>r.name==="https"))==null?void 0:e.href)??null,sshUrl:((t=s.links.clone.find(r=>r.name==="ssh"))==null?void 0:t.href)??null,defaultBranch:{name:s.mainbranch.name},permission:null}},Ye=s=>{let e=s.id;return{id:e.toString(),title:s.title,number:e,state:Lr[s.state],isDraft:!1,commentCount:s.comment_count,upvoteCount:null,author:Wt(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}},Z=class extends A{async refreshToken(e){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 ${e.base64ClientIDColonClientSecret}`},body:`grant_type=refresh_token&refresh_token=${e.refreshToken}`})).body}}async getCurrentUser(e={},t={}){let r=await this.config.request({url:`${G}/user`,headers:L(this.config,t)});return{data:Wt(r.body)}}async getUserForCommit(e,t={}){var i;let n=(await this.config.request({url:`${G}/repositories/${e.repo.namespace}/${e.repo.name}/commit/${e.oid}`,headers:L(this.config,t)})).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(e,t={}){let r=await this.config.request({url:`${G}/repositories/${e.namespace}/${e.name}`,headers:L(this.config,t)});return{data:Ht(r.body)}}async getRepos(e,t={}){let r=[],n=[];return await Promise.all(e.map(async o=>{try{let i=await this.getRepo(o,t);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForCurrentUser(e,t={}){let r=new URL(`${G}/repositories`);r.searchParams.set("role","member"),r.searchParams.set("pagelen",v.toString()),e.cursor&&r.searchParams.set("after",e.cursor);let n=await this.config.request({url:r.toString(),headers:L(this.config,t)}),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(Ht)}}async getBranches(e,t={}){var i;let r=new URL(`${G}/repositories/${e.repo.namespace}/${e.repo.name}/refs/branches`);r.searchParams.set("page",((i=e.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen",v.toString());let n=await this.config.request({url:r.toString(),headers:L(this.config,t)}),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(e,t={}){let r=new URL(`${G}/repositories/${e.repo.namespace}/${e.repo.name}/refs/tags`);r.searchParams.set("pagelen",v.toString()),e.cursor&&r.searchParams.set("page",e.cursor);let n=await this.config.request({url:r.toString(),headers:L(this.config,t)}),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(e,t={}){var i;let r=new URL(`${G}/pullrequests/${e.userId}`);r.searchParams.set("page",((i=e.page)==null?void 0:i.toString())||"1"),r.searchParams.set("pagelen","50");let n=await this.config.request({url:r.toString(),headers:L(this.config,t)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(Ye)}}async getPullRequestsForRepoBase(e,t={}){var n;let r=new URL(`${G}/repositories/${encodeURI(e.repo.namespace)}/${encodeURI(e.repo.name)}/pullrequests?state=OPEN`);return r.searchParams.set("page",((n=e.page)==null?void 0:n.toString())||"1"),r.searchParams.set("pagelen","50"),await this.config.request({url:r.toString(),headers:L(this.config,t)})}async getPullRequestsForRepo(e,t={}){let r=[],n=await this.getPullRequestsForRepoBase(e,t);n.body.values.forEach(i=>{if(e.authorLogin&&i.author.uuid!==e.authorLogin)return null;r.push(Ye(i))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:r}}async getPullRequestsForRepos(e,t={}){let r=[];return await Promise.all(e.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...e},t)).body.values.forEach(i=>{if(e.authorLogin&&i.author.uuid!==e.authorLogin)return null;r.push(Ye(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async closePullRequest(e,t={}){let{pullRequest:r}=e;if(!(await this.config.request({method:"POST",url:`${G}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/decline`,headers:L(this.config,t)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(e,t={}){let{pullRequest:r,mergeStrategy:n}=e,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:`${G}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}/merge`,body:JSON.stringify(i),headers:{...L(this.config,t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(e,t={}){let{pullRequest:r,reviewers:n}=e,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:`${G}/repositories/${r.repository.owner.login}/${r.repository.name}/pullrequests/${r.id}`,body:JSON.stringify(o),headers:{...L(this.config,t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var et=s=>({name:s.displayName,email:s.emailAddress,avatarUrl:s.avatarUrl??null,id:s.id.toString(),username:s.name,url:s.links.self[0].href}),Ze=s=>{var u,l,p,d,c,g;let e={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},t={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},r=s.reviewers.map(m=>({reviewer:et(m.user),state:t[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:e[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:et(s.author.user),assignees:null,reviews:r,reviewDecision:F(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}},Jt=s=>{var e,t,r;return{id:s.id.toString(),namespace:s.project.key,name:s.slug,webUrl:((e=s.links.self[0])==null?void 0:e.href)??null,httpsUrl:((t=s.links.clone.find(n=>n.name==="https"))==null?void 0:t.href)??null,sshUrl:((r=s.links.clone.find(n=>n.name==="ssh"))==null?void 0:r.href)??null,defaultBranch:null,permission:null}},ee=class extends k{getBaseUrl(e){let t=e.baseUrl||this.config.baseUrl;if(!t)throw new Error('Bitbucket Server requires "baseUrl"');return t}getRequestHeaders(e){return f(e.token||this.config.token)}async getCurrentUser(e={},t={}){let r=await this.config.request({url:`${this.getBaseUrl(t)}/users?limit=2`,headers:this.getRequestHeaders(t)}),{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(t)}/users?filter=${o}&avatarSize=64`,headers:this.getRequestHeaders(t)})).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:et(l)}}async getRepo(e,t={}){let r=await this.config.request({url:`${this.getBaseUrl(t)}/projects/${e.namespace}/repos/${e.name}`,headers:this.getRequestHeaders(t)});return{data:Jt(r.body)}}async getRepos(e,t={}){let r=[],n=[];return await Promise.all(e.map(async o=>{try{let i=await this.getRepo(o,t);r.push(i.data)}catch(i){n.push({input:o,error:i})}})),{data:r,errors:n}}async getReposForCurrentUser(e,t={}){let r=e.page??0,n=await this.config.request({url:`${this.getBaseUrl(t)}/repos?start=${r}`,headers:this.getRequestHeaders(t)});return{pageInfo:{hasNextPage:!n.body.isLastPage,nextPage:n.body.nextPageStart},data:n.body.values.map(Jt)}}async getPullRequestsForRepoBase(e,t={}){var n;let r=new URL(`${this.getBaseUrl(t)}/projects/${encodeURI(e.repo.namespace)}/repos/${encodeURI(e.repo.name)}/pull-requests?state=OPEN`);return r.searchParams.set("start",((n=e.page)==null?void 0:n.toString())||"0"),r.searchParams.set("limit","50"),await this.config.request({url:r.toString(),headers:this.getRequestHeaders(t)})}async getPullRequestsForRepo(e,t={}){let r=[],n=await this.getPullRequestsForRepoBase(e,t);n.body.values.forEach(i=>{if(e.authorLogin&&i.author.user.name!==e.authorLogin)return null;r.push(Ze(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(e,t={}){let r=[];return await Promise.all(e.repos.map(async n=>{try{(await this.getPullRequestsForRepoBase({repo:n,...e},t)).body.values.forEach(i=>{if(e.authorLogin&&i.author.user.name!==e.authorLogin)return null;r.push(Ze(i))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async getPullRequestsForCurrentUser(e,t={}){var i;let r=new URL(`${this.getBaseUrl(t)}/dashboard/pull-requests`);r.searchParams.set("state","OPEN"),r.searchParams.set("start",((i=e.page)==null?void 0:i.toString())||"0"),r.searchParams.set("limit","50");let n=await this.config.request({url:r.toString(),headers:this.getRequestHeaders(t)}),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(Ze)}}async closePullRequest(e,t={}){let{pullRequest:r}=e;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(t)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}/decline`,body:JSON.stringify({version:r.version}),headers:{...this.getRequestHeaders(t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(e,t={}){let{pullRequest:r,mergeStrategyId:n}=e;if(e.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(t)}/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(t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async getMergeStrategies(e={}){let t=await this.config.request({url:`${this.getBaseUrl(e)}/admin/pull-requests/git`,headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}});return{data:{defaultStrategy:t.body.mergeConfig.defaultStrategy,strategies:t.body.mergeConfig.strategies}}}async setPullRequestReviewers(e,t={}){let{pullRequest:r,reviewers:n}=e;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(t)}/projects/${r.repository.owner.login}/repos/${r.repository.name}/pull-requests/${r.id}`,body:JSON.stringify(o),headers:{...this.getRequestHeaders(t),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var Yt=require("js-base64");var de=(t=>(t.Open="OPEN",t.Closed="CLOSED",t))(de||{});var Ur={AS_CODE_OWNER:[3,0,0],CHECK_RUN:[3,0,0],LATEST_REVIEWS:[3,0,0],VIEWER_CAN_MERGE_AS_ADMIN:[3,5,0]},ce=(s,e)=>{let t=Ur[e];for(let r=0;r<3;r++){if(s[r]>t[r])return!0;if(s[r]<t[r])return!1}return!0},me="https://api.github.com",$r=`${me}/graphql`,he=`
|
|
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
|
+
`,Ar=`
|
|
10
10
|
... on CheckRun {
|
|
11
11
|
completedAt
|
|
12
12
|
conclusion
|
|
@@ -15,39 +15,39 @@ url
|
|
|
15
15
|
permalink
|
|
16
16
|
startedAt
|
|
17
17
|
}
|
|
18
|
-
`,
|
|
18
|
+
`,ge=/\/api\/v\d+$/,fe=`
|
|
19
19
|
color
|
|
20
20
|
description
|
|
21
21
|
id
|
|
22
22
|
name
|
|
23
|
-
`,
|
|
23
|
+
`,Vt=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.")},Gr=(s,e)=>{let t=e.baseUrl||s.baseUrl;return t?(t=t.replace(/\/$/,""),Vt(t),ge.test(t)&&(t=t.replace(ge,"")),`${t}/api/graphql`):$r},tt=(s,e)=>{let t=e.baseUrl||s.baseUrl;return t?(t=t.replace(/\/$/,""),Vt(t),ge.test(t)&&(t=t.replace(ge,"")),`${t}/api/v3`):me},R=(s,e,t)=>{let r=f(t.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:Gr(s,t),method:"POST",headers:r,body:JSON.stringify(e)})},Or={user:!0,"user:email":!0,"read:user":!0},Q=s=>s.some(e=>Or[e]),O=(s=!1,e=!1,t)=>`
|
|
24
24
|
__typename
|
|
25
|
-
${
|
|
26
|
-
${
|
|
27
|
-
${
|
|
28
|
-
${
|
|
29
|
-
${
|
|
30
|
-
${
|
|
31
|
-
${
|
|
32
|
-
`,
|
|
25
|
+
${z(t,["graphQLId"],"id")}
|
|
26
|
+
${z(t,["id"],"databaseId")}
|
|
27
|
+
${z(t,["name"],"name")}
|
|
28
|
+
${z(t,["name","username"],"login")}
|
|
29
|
+
${e?z(t,["email"],"email"):""}
|
|
30
|
+
${z(t,["avatarUrl"],`avatarUrl${s?"(size: $avatarSize)":""}`)}
|
|
31
|
+
${z(t,["url"],"url")}
|
|
32
|
+
`,Tr=(s=!1)=>`
|
|
33
33
|
latestReviews(first: 100) {
|
|
34
34
|
nodes {
|
|
35
35
|
author {
|
|
36
36
|
... on User {
|
|
37
|
-
${
|
|
37
|
+
${O(!1,s)}
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
state
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
`,
|
|
43
|
+
`,Kt=(s=!1)=>`
|
|
44
44
|
__typename
|
|
45
45
|
id
|
|
46
46
|
databaseId
|
|
47
47
|
login
|
|
48
|
-
avatarUrl${
|
|
48
|
+
avatarUrl${s?"(size: $avatarSize)":""}
|
|
49
49
|
url
|
|
50
|
-
`,
|
|
50
|
+
`,Ie=(s,e=!1,t)=>`
|
|
51
51
|
id
|
|
52
52
|
databaseId
|
|
53
53
|
number
|
|
@@ -55,10 +55,10 @@ title
|
|
|
55
55
|
state
|
|
56
56
|
author {
|
|
57
57
|
... on User {
|
|
58
|
-
${
|
|
58
|
+
${O(!1,e)}
|
|
59
59
|
}
|
|
60
60
|
... on Bot {
|
|
61
|
-
${
|
|
61
|
+
${Kt(!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
|
-
${!
|
|
74
|
+
${!t||ce(t,"CHECK_RUN")?Ar:""}
|
|
75
75
|
... on StatusContext {
|
|
76
76
|
context
|
|
77
77
|
createdAt
|
|
@@ -119,7 +119,7 @@ headRepository {
|
|
|
119
119
|
url
|
|
120
120
|
sshUrl
|
|
121
121
|
}
|
|
122
|
-
${
|
|
122
|
+
${s?"isDraft":""}
|
|
123
123
|
url
|
|
124
124
|
createdAt
|
|
125
125
|
comments {
|
|
@@ -133,44 +133,44 @@ closedAt
|
|
|
133
133
|
mergedAt
|
|
134
134
|
assignees(first: 100) {
|
|
135
135
|
nodes {
|
|
136
|
-
${
|
|
136
|
+
${O(!1,e)}
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
139
|
reviewRequests(first: 100) {
|
|
140
140
|
nodes {
|
|
141
|
-
${!
|
|
141
|
+
${!t||ce(t,"AS_CODE_OWNER")?"asCodeOwner":""}
|
|
142
142
|
requestedReviewer {
|
|
143
143
|
... on User {
|
|
144
|
-
${
|
|
144
|
+
${O(!1,e)}
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
${!
|
|
149
|
+
${!t||ce(t,"LATEST_REVIEWS")?Tr(e):""}
|
|
150
150
|
additions
|
|
151
151
|
deletions
|
|
152
152
|
changedFiles
|
|
153
153
|
mergeable
|
|
154
154
|
mergeStateStatus
|
|
155
155
|
milestone {
|
|
156
|
-
${
|
|
156
|
+
${he}
|
|
157
157
|
}
|
|
158
158
|
labels(first: 100) {
|
|
159
159
|
nodes {
|
|
160
|
-
${
|
|
160
|
+
${fe}
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
|
-
${!
|
|
164
|
-
`,
|
|
163
|
+
${!t||ce(t,"VIEWER_CAN_MERGE_AS_ADMIN")?"viewerCanMergeAsAdmin":""}
|
|
164
|
+
`,kr=(s=!1)=>`
|
|
165
165
|
id
|
|
166
166
|
databaseId
|
|
167
167
|
title
|
|
168
168
|
author {
|
|
169
169
|
... on User {
|
|
170
|
-
${
|
|
170
|
+
${O(!1,s)}
|
|
171
171
|
}
|
|
172
172
|
... on Bot {
|
|
173
|
-
${
|
|
173
|
+
${Kt(!1)}
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
closedAt
|
|
@@ -194,19 +194,19 @@ comments {
|
|
|
194
194
|
}
|
|
195
195
|
assignees(first: 100) {
|
|
196
196
|
nodes {
|
|
197
|
-
${
|
|
197
|
+
${O(!1,s)}
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
200
|
state
|
|
201
201
|
milestone {
|
|
202
|
-
${
|
|
202
|
+
${he}
|
|
203
203
|
}
|
|
204
204
|
labels(first: 100) {
|
|
205
205
|
nodes {
|
|
206
|
-
${
|
|
206
|
+
${fe}
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
-
`,
|
|
209
|
+
`,xr={"-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"},_r=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),rt=s=>{let e=[];return(s.match(_r)??[]).forEach(r=>{if(r.includes(":")&&r!="is:closed"){let n=r.split(":")[0];xr[n]&&e.push(r)}}),e},st=(s,e,t,r,n=!1,o=null)=>{let i=s==="issue";return{query:`
|
|
210
210
|
query SearchIssuesOrPullRequests($query: String! $after: String) {
|
|
211
211
|
search(type:ISSUE query:$query first:100 after:$after) {
|
|
212
212
|
pageInfo {
|
|
@@ -214,19 +214,19 @@ query SearchIssuesOrPullRequests($query: String! $after: String) {
|
|
|
214
214
|
endCursor
|
|
215
215
|
}
|
|
216
216
|
nodes {
|
|
217
|
-
... on ${
|
|
218
|
-
${
|
|
217
|
+
... on ${i?"Issue":"PullRequest"} {
|
|
218
|
+
${i?kr(r):Ie(n,r,o)}
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
|
-
}`,variables:{query:`is:${
|
|
222
|
+
}`,variables:{query:`is:${s} is:open ${e}`,after:t}}},Nr="Field 'isDraft' doesn't exist on type 'PullRequest'",Re=(s=[])=>s.some(e=>(e==null?void 0:e.message)===Nr),Qr=/@@ -(\d+)(?:,\d+ | )\+(\d+)(?:,\d+ | )@@(?:\\n)?/,Br=`
|
|
223
223
|
\
|
|
224
|
-
+`,
|
|
224
|
+
+`,Xt=(s,e,t,r)=>{let n=Qr.exec(s);if(!n||!n[0]||!n[1])return[];let o=parseInt(n[1],10),i=parseInt(n[2],10),a=s.replace(Br,`
|
|
225
225
|
+`).split(`
|
|
226
|
-
`).slice(1),u=o-1,l=
|
|
227
|
-
`;break}case"+":{m="ADDED",l+=1,
|
|
228
|
-
`;break}default:m="UNMODIFIED",l+=1,u+=1,
|
|
229
|
-
`}return{line:
|
|
226
|
+
`).slice(1),u=o-1,l=i-1,p=a.map(g=>{let m,I;switch(g[0]){case"-":{m="DELETED",u+=1,I=`${g.slice(1)}
|
|
227
|
+
`;break}case"+":{m="ADDED",l+=1,I=`${g.slice(1)}
|
|
228
|
+
`;break}default:m="UNMODIFIED",l+=1,u+=1,I=`${g}
|
|
229
|
+
`}return{line:I,oldLineNumber:m!=="ADDED"?u:null,newLineNumber:m!=="DELETED"?l:null,type:m}}),d=t,c=e;if(d!==null&&c!==null&&r!==null&&d<c){let g=0,m=p.length,I=r==="LEFT"?"oldLineNumber":"newLineNumber";for(let P=0;P<p.length;P++){let b=p[P][I];b===d?g=P:b===c&&(m=P)}p=p.slice(g,m+1)}return p};var nt=`
|
|
230
230
|
id
|
|
231
231
|
databaseId
|
|
232
232
|
owner {
|
|
@@ -239,18 +239,18 @@ defaultBranchRef {
|
|
|
239
239
|
name
|
|
240
240
|
}
|
|
241
241
|
viewerPermission
|
|
242
|
-
`,
|
|
242
|
+
`,at={__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"},jr={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},Mr={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},Fr={BEHIND:"BEHIND",BLOCKED:"BLOCKED",UNKNOWN:"UNKNOWN_AND_BLOCKED",UNSTABLE:"UNSTABLE",CLEAN:null,DIRTY:null,DRAFT:null,HAS_HOOKS:null},zr={OPEN:"OPEN",CLOSED:"CLOSED"},Hr=["ADMIN","MAINTAIN","TRIAGE","WRITE"],ut=s=>({color:s.color,description:s.description,graphQLId:s.id,id:null,name:s.name}),ot=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}),Wr={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},Jr={id:!0,graphQLId:!0,name:!0,username:!0,email:!0,avatarUrl:!0,url:!0},x=(s,e=Jr)=>{let t={};return e.id&&(t.id=s.databaseId.toString()),e.graphQLId&&(t.graphQLId=s.id),e.name&&(t.name=s.name??s.login),e.username&&(t.username=s.login),e.email&&(t.email=s.email??null),e.avatarUrl&&(t.avatarUrl=s.avatarUrl),e.url&&(t.url=s.url),t},Vr=(s,e)=>{let t={IN_PROGRESS:"RUNNING",PENDING:"PENDING",QUEUED:"PENDING",REQUESTED:"PENDING",WAITING:"PENDING"};return s!=="COMPLETED"?t[s]:{ACTION_REQUIRED:"ACTION_REQUIRED",CANCELLED:"CANCELLED",FAILURE:"FAILED",NEUTRAL:null,SKIPPED:"SKIPPED",STALE:"FAILED",STARTUP_FAILURE:"FAILED",SUCCESS:"SUCCESS",TIMED_OUT:"ERROR"}[e]},Kr=s=>({ERROR:"ERROR",EXPECTED:"PENDING",FAILURE:"FAILED",PENDING:"PENDING",SUCCESS:"SUCCESS"})[s],it=s=>{var i,a,u,l,p,d,c,g,m,I,P;let e=null;s.author?e=(s.author.__typename==="Bot",s.author):e=at;let t=(((i=s.reviewRequests)==null?void 0:i.nodes)||[]).filter(h=>!h.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=t.filter(h=>h.requestedReviewer&&"__typename"in h.requestedReviewer).map(h=>({reviewer:x(h.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((((l=s.latestReviews)==null?void 0:l.nodes)||[]).map(h=>{let b=at;return h.author&&Object.keys(h.author).length>0&&(b=h.author),{reviewer:x(b),state:jr[h.state]}}));return{id:s.databaseId.toString(),graphQLId:s.id,title:s.title,number:s.number,state:Wr[s.state],commentCount:s.comments.totalCount,upvoteCount:s.reactions.totalCount,author:e?x(e):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:((c=(d=(p=s.commits.nodes)==null?void 0:p[0].commit.statusCheckRollup)==null?void 0:d.contexts.nodes)==null?void 0:c.map(h=>"context"in h?{completedAt:null,description:h.description,name:h.context,state:Kr(h.state),startedAt:new Date(h.createdAt),stage:null,url:h.targetUrl}:{completedAt:h.completedAt?new Date(h.completedAt):null,description:null,name:h.name,state:Vr(h.status,h.conclusion),startedAt:h.startedAt?new Date(h.startedAt):null,stage:null,url:h.permalink}))??[]},headRef:s.headRef?{name:s.headRef.name,oid:((g=s.headRef.target)==null?void 0:g.oid)??null}:null,baseRef:s.baseRef?{name:s.baseRef.name,oid:((m=s.baseRef.target)==null?void 0:m.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.map(h=>x(h)):null,reviews:o,reviewDecision:F(o),additions:s.additions,deletions:s.deletions,fileCount:s.changedFiles,commitCount:s.commits.totalCount,mergeableState:Fr[s.mergeStateStatus]??Mr[s.mergeable],milestone:s.milestone?lt(s.milestone):null,labels:((P=(I=s.labels)==null?void 0:I.nodes)==null?void 0:P.map(ut))??[],permissions:{canMerge:Hr.includes(s.repository.viewerPermission),canMergeAndBypassProtections:s.viewerCanMergeAsAdmin??!1}}},Xr=s=>{let{comments:e,isOutdated:t,isResolved:r,originalLine:n,originalStartLine:o,startDiffSide:i}=s,{author:a,body:u,databaseId:l,id:p,path:d,publishedAt:c,url:g}=e.nodes[0];return{author:a?{avatarUrl:a.avatarUrl,email:null,name:a.login}:null,body:u,createdAt:c?new Date(c):null,diffLines:Xt(e.nodes[0].diffHunk,n,o,i),id:l,isOutdated:t,isResolved:r,graphQLId:p,filename:d,replies:e.nodes.slice(1).map(Yr),url:g}},Yr=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}),Zr=s=>{var t,r;let e=null;return s.author?e=(s.author.__typename==="Bot",s.author):e=at,{id:s.databaseId.toString(),graphQLId:s.id,number:s.number,title:s.title,author:x(e),commentCount:s.comments.totalCount,closedDate:s.closedAt?new Date(s.closedAt):null,createdDate:new Date(s.createdAt),description:null,state:{name:zr[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:s.assignees.nodes?s.assignees.nodes.map(n=>x(n)):[],upvoteCount:s.reactions.totalCount,milestone:s.milestone?lt(s.milestone):null,labels:((r=(t=s.labels)==null?void 0:t.nodes)==null?void 0:r.map(ut))??[]}},lt=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}),te=class extends k{constructor(){super(...arguments);this._scopesCache={};this._enterpriseVersionsCache={}}async getScopes(t){let r=t.token||this.config.token;if(!r)return[];let n=this._scopesCache[r];if(!n){let i=(await R(this.config,{query:"query { rateLimit(dryRun: true) { __typename } }"},t)).headers["x-oauth-scopes"];n=i?i.split(", "):[],this._scopesCache[r]=n}return n}async getEnterpriseVersion(t){let r=t.baseUrl||this.config.baseUrl;if(!r)return null;let n=this._enterpriseVersionsCache[r];if(!n){let o=await this.config.request({url:`${tt(this.config,t)}/meta`,headers:f(t.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(t,r,n){let o=n.baseUrl||this.config.baseUrl;return!o||o.startsWith(me)?t:r?`https://avatars.githubusercontent.com/u/e?email=${encodeURIComponent(r)}`:""}async getCurrentUser(t={},r={}){var u;if(t.fields&&!t.fields.length)throw new Error('"fields" must contain at least one field or be omitted');let n=jt(t.fields),o=await this.getScopes(r),a=(u=(await R(this.config,{query:`
|
|
243
243
|
query getCurrentUser {
|
|
244
244
|
viewer {
|
|
245
|
-
${
|
|
245
|
+
${O(!1,Q(o),n)}
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
|
-
`},
|
|
248
|
+
`},r)).body.data)==null?void 0:u.viewer;if(!a)throw new Error("Current user not found.");return{data:x(a,n)}}async getAccountsForRepo(t,r={}){var l,p,d,c,g,m;let n=await this.getScopes(r),{repo:{namespace:o,name:i},cursor:a}=t,u=await R(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) {
|
|
252
252
|
nodes {
|
|
253
|
-
${
|
|
253
|
+
${O(!1,Q(n))}
|
|
254
254
|
}
|
|
255
255
|
pageInfo {
|
|
256
256
|
endCursor
|
|
@@ -259,7 +259,7 @@ query getAccountsForRepo($owner: String!, $name: String! $cursor: String, $first
|
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
|
-
`,variables:{owner:o,name:
|
|
262
|
+
`,variables:{owner:o,name:i,cursor:a,first:v}},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(I=>x(I)))??[]}}async getUserForCommit(t,r={}){var a,u;let o=(a=(await R(this.config,{query:`
|
|
263
263
|
query getUserForCommit(
|
|
264
264
|
$owner: String!
|
|
265
265
|
$name: String!
|
|
@@ -278,7 +278,7 @@ query getUserForCommit(
|
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
|
-
`,variables:{owner:
|
|
281
|
+
`,variables:{owner:t.repo.namespace,name:t.repo.name,oid:t.oid,avatarSize:t.avatarSize}},r)).body.data)==null?void 0:a.repository;if(!o)throw new Error("Repository not found.");let i=(u=o.object)==null?void 0:u.author;if(!i)throw new Error("Commit not found.");return{data:{name:i.name,email:i.email,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(i.avatarUrl,i.email,r)}}}async createCommit(t,r={}){var p;let{commitMessage:n,deletedFiles:o,newOrModifiedFiles:i,repo:a,target:u}=t,l=await R(this.config,{query:`
|
|
282
282
|
mutation createCommitOnBranch(
|
|
283
283
|
$branchName: String!,
|
|
284
284
|
$expectedHeadOid: GitObjectID!,
|
|
@@ -305,23 +305,23 @@ mutation createCommitOnBranch(
|
|
|
305
305
|
}
|
|
306
306
|
}
|
|
307
307
|
}
|
|
308
|
-
`,variables:{branchName:u.name,expectedHeadOid:u.oid,fileChanges:{additions:Object.entries(
|
|
308
|
+
`,variables:{branchName:u.name,expectedHeadOid:u.oid,fileChanges:{additions:Object.entries(i).map(([d,c])=>({contents:Yt.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(t,r={}){var a,u,l;let n=await this.getScopes(r),i=(l=(u=(a=(await R(this.config,{query:`
|
|
309
309
|
query getAccountForEmail($query: String! $avatarSize: Int) {
|
|
310
310
|
search(query: $query, type: USER, first: 1) {
|
|
311
311
|
nodes {
|
|
312
312
|
... on User {
|
|
313
|
-
${
|
|
313
|
+
${O(!0,Q(n))}
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
|
-
`,variables:{query:`in:email ${
|
|
318
|
+
`,variables:{query:`in:email ${t.email}`,avatarSize:t.avatarSize}},r)).body.data)==null?void 0:a.search)==null?void 0:u.nodes)==null?void 0:l[0];if(!i)throw new Error("User not found.");return{data:x({...i,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(i.avatarUrl,i.email,r)})}}async getAccountForUsername(t,r={}){var a;let n=await this.getScopes(r),i=(a=(await R(this.config,{query:`
|
|
319
319
|
query getUserForUsername($login: String! $avatarSize: Int) {
|
|
320
320
|
user(login: $login) {
|
|
321
|
-
${
|
|
321
|
+
${O(!0,Q(n))}
|
|
322
322
|
}
|
|
323
323
|
}
|
|
324
|
-
`,variables:{login:
|
|
324
|
+
`,variables:{login:t.username,avatarSize:t.avatarSize}},r)).body.data)==null?void 0:a.user;if(!i)throw new Error("User not found.");return{data:x({...i,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(i.avatarUrl,i.email,r)})}}async getOrgsForCurrentUser(t={},r={}){var i,a;let n=await R(this.config,{query:`
|
|
325
325
|
query getOrgsForCurrentUser($cursor: String, $first: Int!) {
|
|
326
326
|
viewer {
|
|
327
327
|
organizations(first: $first after: $cursor) {
|
|
@@ -340,22 +340,22 @@ query getOrgsForCurrentUser($cursor: String, $first: Int!) {
|
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
|
-
`,variables:{cursor:
|
|
343
|
+
`,variables:{cursor:t.cursor,first:v}},r);if(!((i=n.body.data)!=null&&i.viewer.organizations))throw new Error(((a=n.body.errors)==null?void 0:a[0].message)||n.statusText||"Unknown error");let o=n.body.data.viewer.organizations.nodes||[];return{pageInfo:n.body.data.viewer.organizations.pageInfo,data:o.map(u=>({id:u.databaseId.toString(),graphQLId:u.id,username:u.login,name:u.name||null,email:u.email||null,avatarUrl:u.avatarUrl}))}}async getRepo(t,r={}){var o;let n=await R(this.config,{query:`
|
|
344
344
|
query getRepo($owner: String!, $name: String!) {
|
|
345
345
|
repository(owner: $owner, name: $name) {
|
|
346
|
-
${
|
|
346
|
+
${nt}
|
|
347
347
|
}
|
|
348
348
|
}
|
|
349
|
-
`,variables:{owner:
|
|
349
|
+
`,variables:{owner:t.namespace,name:t.name}},r);if(!((o=n.body.data)!=null&&o.repository))throw new Error(`Repository ${t.namespace}/${t.name} not found`);return{data:ot(n.body.data.repository)}}async getRepos(t,r={}){let n=t.map(({namespace:u,name:l},p)=>`
|
|
350
350
|
getRepo_${p}: repository(owner: "${u}", name: "${l}") {
|
|
351
|
-
${
|
|
351
|
+
${nt}
|
|
352
352
|
}
|
|
353
353
|
`).join(`
|
|
354
|
-
`),o=await
|
|
354
|
+
`),o=await R(this.config,{query:`
|
|
355
355
|
query batchGetRepos {
|
|
356
356
|
${n}
|
|
357
357
|
}
|
|
358
|
-
`},
|
|
358
|
+
`},r);if(!o.body.data)throw new Error(o.statusText||"Unknown error");let i=[],a=[];return t.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?i.push(ot(p)):a.push({input:u})}),{data:i,errors:a}}async getReposForUsernames(t,r={}){var i;if(!t.usernames.length)return{pageInfo:{endCursor:null,hasNextPage:!1},data:[]};let n=await R(this.config,{query:`
|
|
359
359
|
query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
|
|
360
360
|
search(query: $query, type: REPOSITORY, first: $first, after: $cursor) {
|
|
361
361
|
pageInfo {
|
|
@@ -364,12 +364,12 @@ query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
|
|
|
364
364
|
}
|
|
365
365
|
nodes {
|
|
366
366
|
... on Repository {
|
|
367
|
-
${
|
|
367
|
+
${nt}
|
|
368
368
|
}
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
371
|
}
|
|
372
|
-
`,variables:{query:`fork:true ${
|
|
372
|
+
`,variables:{query:`fork:true ${t.usernames.map(a=>`user:${a}`).join(" ")}`,cursor:t.cursor,first:v}},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(ot)}}async getReposForOwners(t,r={}){return this.getReposForUsernames({usernames:t.owners.filter(n=>n.username).map(n=>n.username),cursor:t.cursor},r)}async getRefs(t,r,n={}){var u;let i=(u=(await R(this.config,{query:`
|
|
373
373
|
query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: String, $first: Int!) {
|
|
374
374
|
repository(owner: $owner, name: $name) {
|
|
375
375
|
refs(refPrefix: $refPrefix first: $first after: $cursor) {
|
|
@@ -390,7 +390,7 @@ query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: Str
|
|
|
390
390
|
}
|
|
391
391
|
}
|
|
392
392
|
}
|
|
393
|
-
`,variables:{owner:
|
|
393
|
+
`,variables:{owner:r.repo.namespace,name:r.repo.name,refPrefix:t,cursor:r.cursor,first:v}},n)).body.data)==null?void 0:u.repository;if(!i)throw new Error("Repository not found.");let a=i.refs;return a?{pageInfo:a.pageInfo,data:(a.nodes||[]).map(l=>{var d;let p=(d=l.target)!=null&&d.oid?l.target:null;return{name:l.name,commit:p?{oid:p.oid,authoredDate:new Date(p.authoredDate),committedDate:new Date(p.committedDate)}:null}})}:{pageInfo:{endCursor:null,hasNextPage:!1},data:[]}}async getBranches(t,r={}){return this.getRefs("refs/heads/",t,r)}async getTags(t,r={}){return this.getRefs("refs/tags/",t,r)}async getBlame(t,r={}){var a;let o=(a=(await R(this.config,{query:`
|
|
394
394
|
query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
395
395
|
repository(owner: $owner, name: $name) {
|
|
396
396
|
object(expression: $ref) {
|
|
@@ -429,7 +429,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
429
429
|
}
|
|
430
430
|
}
|
|
431
431
|
}
|
|
432
|
-
`,variables:{owner:
|
|
432
|
+
`,variables:{owner:t.repo.namespace,name:t.repo.name,ref:t.ref,path:t.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(t,r={}){let n=await this.config.request({url:`${tt(this.config,r)}/repos/${t.repo.namespace}/${t.repo.name}/contents/${encodeURIComponent(t.path)}?ref=${t.ref}`,headers:{...f(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 "${t.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 "${t.path}"`);return{data:new Blob([n.body])}}async searchPullRequests(t,r={}){var p,d;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),i=Q(o),a=c=>{let g=c&&typeof t.isDraft=="boolean"?`${t.query} draft:${t.isDraft}`:t.query;return st("pr",g,t.cursor,i,c,n)},u=await R(this.config,a(!0),r);u.body.errors&&Re(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await R(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.map(it))||[]}}async searchIssues(t,r={}){var u,l;let n=await this.getScopes(r),o=Q(n),i=await R(this.config,st("issue",t.query,t.cursor,o),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(Zr))||[]}}async getPullRequestsAssociatedWithUser(t,r={}){return this.searchPullRequests({query:`involves:${t.username}`,cursor:t.cursor},r)}async getPullRequestsForRepos(t,r={}){let{assigneeLogins:n,updatedBefore:o,authorLogin:i,repos:a,reviewRequestedLogin:u,startQuery:l,mentionLogin:p}=t,d=rt(l||"");return a.forEach(c=>{d.push(`repo:${c.namespace}/${c.name}`)}),n&&n.forEach(c=>{d.push(`assignee:${c}`)}),o&&d.push(`updated:<${o}`),i&&d.push(`author:${i}`),u&&d.push(`review-requested:${u}`),p&&d.push(`mentions:${p}`),this.searchPullRequests({query:`sort:updated ${d.join(" ")}`,isDraft:t.isDraft,cursor:t.cursor},r)}async getPullRequestForRepo(t,r={}){var d,c;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),i=Q(o),a=g=>({query:`query getPullRequest(
|
|
433
433
|
$owner: String!
|
|
434
434
|
$name: String!
|
|
435
435
|
$number: Int!
|
|
@@ -439,24 +439,24 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
439
439
|
name: $name
|
|
440
440
|
) {
|
|
441
441
|
pullRequest(number: $number) {
|
|
442
|
-
${
|
|
442
|
+
${Ie(g,i,n)}
|
|
443
443
|
}
|
|
444
444
|
}
|
|
445
|
-
}`,variables:{owner:
|
|
445
|
+
}`,variables:{owner:t.repo.namespace,name:t.repo.name,number:t.number}}),u=await R(this.config,a(!0),r);u.body.errors&&Re(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await R(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?it(p):null}}async getPullRequestByGraphQLId(t,r={}){var d,c;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),i=Q(o),a=g=>({query:`query getPullRequest(
|
|
446
446
|
$graphQLId: ID!
|
|
447
447
|
) {
|
|
448
448
|
node(id: $graphQLId) {
|
|
449
449
|
... on PullRequest {
|
|
450
|
-
${
|
|
450
|
+
${Ie(g,i,n)}
|
|
451
451
|
}
|
|
452
452
|
}
|
|
453
|
-
}`,variables:{graphQLId:
|
|
453
|
+
}`,variables:{graphQLId:t.graphQLId}}),u=await R(this.config,a(!0),r);u.body.errors&&Re(u.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(u=await R(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?it(p):null}}async closePullRequest(t,r={}){var a,u,l;let{pullRequest:{graphQLId:n}}=t;if(!n)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation ClosePullRequest($pullRequestGraphQLId: ID!) {
|
|
454
454
|
closePullRequest(input: { pullRequestId: $pullRequestGraphQLId }) {
|
|
455
455
|
pullRequest {
|
|
456
456
|
id
|
|
457
457
|
}
|
|
458
458
|
}
|
|
459
|
-
}`;if(!((l=(u=(
|
|
459
|
+
}`;if(!((l=(u=(a=(await R(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(t,r={}){var l,p,d,c;let{pullRequest:n,mergeStrategy:o}=t;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(
|
|
460
460
|
$pullRequestGraphQLId: ID!,
|
|
461
461
|
$expectedSourceSha: GitObjectID!,
|
|
462
462
|
$mergeStrategy: PullRequestMergeMethod,
|
|
@@ -470,43 +470,43 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
470
470
|
id
|
|
471
471
|
}
|
|
472
472
|
}
|
|
473
|
-
}`;if(!((c=(d=(p=(await
|
|
473
|
+
}`;if(!((c=(d=(p=(await R(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(t,r={}){var u,l,p;let{pullRequest:n,milestone:o}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation SetPullRequestMilestone($pullRequestGraphQLId: ID!, $milestoneGraphQLId: ID) {
|
|
474
474
|
updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, milestoneId: $milestoneGraphQLId }) {
|
|
475
475
|
pullRequest {
|
|
476
476
|
id
|
|
477
477
|
}
|
|
478
478
|
}
|
|
479
|
-
}`;if(!((p=(l=(u=(await
|
|
479
|
+
}`;if(!((p=(l=(u=(await R(this.config,{query:`${i}`,variables:{pullRequestGraphQLId:n.graphQLId,milestoneGraphQLId:(o==null?void 0:o.graphQLId)??null}},r)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set milestone of pull request")}async markPullRequestReadyForReview(t,r){var i,a,u;let n=`mutation MarkReadyToReview($pullRequestGraphQLId: ID!) {
|
|
480
480
|
markPullRequestReadyForReview(input: { pullRequestId: $pullRequestGraphQLId }) {
|
|
481
481
|
pullRequest {
|
|
482
482
|
id
|
|
483
483
|
}
|
|
484
484
|
}
|
|
485
|
-
}`;if(!((u=(
|
|
485
|
+
}`;if(!((u=(a=(i=(await R(this.config,{query:n,variables:{pullRequestGraphQLId:t}},r)).body.data)==null?void 0:i.markPullRequestReadyForReview)==null?void 0:a.pullRequest)!=null&&u.id))throw new Error("Could not mark pull request ready to review")}async convertPullRequestToDraft(t,r){var i,a,u;let n=`mutation ConvertToDraft($pullRequestGraphQLId: ID!) {
|
|
486
486
|
convertPullRequestToDraft(input: { pullRequestId: $pullRequestGraphQLId }) {
|
|
487
487
|
pullRequest {
|
|
488
488
|
id
|
|
489
489
|
}
|
|
490
490
|
}
|
|
491
|
-
}`;if(!((u=(
|
|
491
|
+
}`;if(!((u=(a=(i=(await R(this.config,{query:n,variables:{pullRequestGraphQLId:t}},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(t,r={}){let{pullRequest:{graphQLId:n},isDraft:o}=t;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(t,r={}){var d,c,g;let{pullRequest:{reviews:n,graphQLId:o},reviewers:i}=t;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!]!) {
|
|
492
492
|
requestReviews(input: { pullRequestId: $pullRequestGraphQLId, userIds: $reviewerGraphQLIds }) {
|
|
493
493
|
pullRequest {
|
|
494
494
|
id
|
|
495
495
|
}
|
|
496
496
|
}
|
|
497
|
-
}`;if(!((g=(c=(d=(await
|
|
497
|
+
}`;if(!((g=(c=(d=(await R(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(t,r={}){var p,d,c;let{pullRequest:{reviews:n,graphQLId:o},reviewers:i}=t;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!]!) {
|
|
498
498
|
requestReviews(input: { pullRequestId: $pullRequestGraphQLId, userIds: $reviewerGraphQLIds, union: true }) {
|
|
499
499
|
pullRequest {
|
|
500
500
|
id
|
|
501
501
|
}
|
|
502
502
|
}
|
|
503
|
-
}`;if(!((c=(d=(p=(await
|
|
503
|
+
}`;if(!((c=(d=(p=(await R(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(t,r={}){var l,p,d;let{pullRequest:n,assignees:o}=t;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!]!) {
|
|
504
504
|
updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, assigneeIds: $assigneeGraphQLIds }) {
|
|
505
505
|
pullRequest {
|
|
506
506
|
id
|
|
507
507
|
}
|
|
508
508
|
}
|
|
509
|
-
}`;if(!((d=(p=(l=(await
|
|
509
|
+
}`;if(!((d=(p=(l=(await R(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(t,r={}){var d,c;let{repo:{namespace:n,name:o},pullRequestId:i}=t,a=`query getPullRequests(
|
|
510
510
|
$namespace: String!
|
|
511
511
|
$name: String!
|
|
512
512
|
$pullRequestId: Int!
|
|
@@ -558,54 +558,54 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
558
558
|
}
|
|
559
559
|
}
|
|
560
560
|
}
|
|
561
|
-
}`,u=await
|
|
561
|
+
}`,u=await R(this.config,{query:a,variables:{namespace:n,name:o,pullRequestId:i}},r),l=((d=u.body.data)==null?void 0:d.repository.pullRequest.reviewThreads.nodes.reduce((g,m)=>{let I=m.comments.nodes[0].pullRequestReview;return I&&(g[I.id]||(g[I.id]=[]),g[I.id].push(Xr(m))),g},{}))??{};return{data:((c=u.body.data)==null?void 0:c.repository.pullRequest.reviews.nodes.filter(g=>l[g.id]).map(g=>({author:g.author?{avatarUrl:g.author.avatarUrl,email:null,name:g.author.login}:null,body:g.body,createdAt:g.publishedAt?new Date(g.publishedAt):null,id:g.databaseId,graphQLId:g.id,reviewComments:l[g.id],url:g.url})))??[]}}async getIssuesAssociatedWithUser(t,r={}){var d;let[n,o]=((d=t.cursor)==null?void 0:d.split(";"))||[void 0,void 0],[i,a]=await Promise.all([n==="null"?null:this.searchIssues({query:`author:${t.username}`,cursor:n},r),o==="null"?null:this.searchIssues({query:`assignee:${t.username}`,cursor:o},r)]),u={},l=[],p=c=>{u[c.id]||(u[c.id]=!0,l.push(c))};return i==null||i.data.forEach(p),a==null||a.data.forEach(p),{pageInfo:{hasNextPage:(i==null?void 0:i.pageInfo.hasNextPage)||(a==null?void 0:a.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"}`},data:l}}async setPullRequestLabels(t,r={}){var u,l,p;let{pullRequest:n,labels:o}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation SetPullRequestLabels($pullRequestGraphQLId: ID!, $labelGraphQLIds: [ID!]) {
|
|
562
562
|
updatePullRequest(input: { pullRequestId: $pullRequestGraphQLId, labelIds: $labelGraphQLIds }) {
|
|
563
563
|
pullRequest {
|
|
564
564
|
id
|
|
565
565
|
}
|
|
566
566
|
}
|
|
567
|
-
}`;if(!((p=(l=(u=(await
|
|
567
|
+
}`;if(!((p=(l=(u=(await R(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(t,r={}){let n=rt(t.startQuery||""),{cursor:o,assigneeLogins:i,updatedBefore:a,authorLogin:u,mentionLogin:l}=t;return t.repos.forEach(p=>{n.push(`repo:${p.namespace}/${p.name}`)}),i&&i.forEach(p=>{n.push(`assignee:${p}`)}),a&&n.push(`updated:<${a}`),u&&n.push(`author:${u}`),l&&n.push(`mentions:${l}`),this.searchIssues({query:`sort:updated ${n.join(" ")}`,cursor:o},r)}async closeIssueWithReason(t,r={}){var u,l,p;let{issue:n,reason:o}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let i=`mutation CloseIssueWithReason($issueGraphQLId: ID!, $reason: IssueClosedStateReason!) {
|
|
568
568
|
closeIssue(input: { issueId: $issueGraphQLId, stateReason: $reason }) {
|
|
569
569
|
issue {
|
|
570
570
|
id
|
|
571
571
|
}
|
|
572
572
|
}
|
|
573
|
-
}`;if(!((p=(l=(u=(await
|
|
573
|
+
}`;if(!((p=(l=(u=(await R(this.config,{query:i,variables:{issueGraphQLId:n.graphQLId,reason:o}},r)).body.data)==null?void 0:u.closeIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not close issue with reason")}async closeIssue(t,r={}){var a,u,l;let{issue:n}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation SetIssueState($issueGraphQLId: ID!) {
|
|
574
574
|
updateIssue(input: { id: $issueGraphQLId, state: CLOSED }) {
|
|
575
575
|
issue {
|
|
576
576
|
id
|
|
577
577
|
}
|
|
578
578
|
}
|
|
579
|
-
}`;if(!((l=(u=(
|
|
579
|
+
}`;if(!((l=(u=(a=(await R(this.config,{query:o,variables:{issueGraphQLId:n.graphQLId}},r)).body.data)==null?void 0:a.updateIssue)==null?void 0:u.issue)!=null&&l.id))throw new Error("Could not close issue")}async reOpenIssue(t,r={}){var a,u,l;let{issue:n}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation ReOpenIssue($issueGraphQLId: ID!) {
|
|
580
580
|
reopenIssue(input: { issueId: $issueGraphQLId }) {
|
|
581
581
|
issue {
|
|
582
582
|
id
|
|
583
583
|
}
|
|
584
584
|
}
|
|
585
|
-
}`;if(!((l=(u=(
|
|
585
|
+
}`;if(!((l=(u=(a=(await R(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(t,r={}){var l,p,d;let{issue:n,labels:o}=t;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!]) {
|
|
586
586
|
updateIssue(input: { id: $issueGraphQLId, labelIds: $labelGraphQLIds }) {
|
|
587
587
|
issue {
|
|
588
588
|
id
|
|
589
589
|
}
|
|
590
590
|
}
|
|
591
|
-
}`;if(!((d=(p=(l=(await
|
|
591
|
+
}`;if(!((d=(p=(l=(await R(this.config,{query:a,variables:{issueGraphQLId:n.graphQLId,labelGraphQLIds:i}},r)).body.data)==null?void 0:l.updateIssue)==null?void 0:p.issue)!=null&&d.id))throw new Error("Could not set issue labels")}async setIssueMilestone(t,r={}){var u,l,p;let{issue:n,milestone:o}=t;if(!n.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');if(o&&!o.graphQLId)throw new Error('GitHub requires milestone "graphQLId" for this function.');let i=`mutation SetIssueMilestone($issueGraphQLId: ID!, $milestoneGraphQLId: ID) {
|
|
592
592
|
updateIssue(input: { id: $issueGraphQLId, milestoneId: $milestoneGraphQLId }) {
|
|
593
593
|
issue {
|
|
594
594
|
id
|
|
595
595
|
}
|
|
596
596
|
}
|
|
597
|
-
}`;if(!((p=(l=(u=(await
|
|
597
|
+
}`;if(!((p=(l=(u=(await R(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(t,r={}){var l,p,d;let{issue:n,assignees:o}=t;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!]!) {
|
|
598
598
|
updateIssue(input: { id: $issueGraphQLId, assigneeIds: $assigneeGraphQLIds }) {
|
|
599
599
|
issue {
|
|
600
600
|
id
|
|
601
601
|
}
|
|
602
602
|
}
|
|
603
|
-
}`;if(!((d=(p=(l=(await
|
|
603
|
+
}`;if(!((d=(p=(l=(await R(this.config,{query:a,variables:{issueGraphQLId:n.graphQLId,assigneeGraphQLIds:i}},r)).body.data)==null?void 0:l.updateIssue)==null?void 0:p.issue)!=null&&d.id))throw new Error("Could not set issue assignees")}async getMilestonesForRepo(t,r={}){var u,l,p,d;let{repo:{namespace:n,name:o},cursor:i}=t,a=await R(this.config,{query:`
|
|
604
604
|
query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
|
|
605
605
|
repository(owner: $owner, name: $name) {
|
|
606
606
|
milestones(first: $first, after: $cursor) {
|
|
607
607
|
nodes {
|
|
608
|
-
${
|
|
608
|
+
${he}
|
|
609
609
|
}
|
|
610
610
|
pageInfo {
|
|
611
611
|
endCursor
|
|
@@ -614,12 +614,12 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
|
|
|
614
614
|
}
|
|
615
615
|
}
|
|
616
616
|
}
|
|
617
|
-
`,variables:{owner:n,name:o,cursor:
|
|
617
|
+
`,variables:{owner:n,name:o,cursor:i,first:v}},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(lt))??[]}}async getLabelsForRepo(t,r={}){var u,l,p,d;let{repo:{namespace:n,name:o},cursor:i}=t,a=await R(this.config,{query:`
|
|
618
618
|
query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
|
|
619
619
|
repository(owner: $owner, name: $name) {
|
|
620
620
|
labels(first: $first, after: $cursor) {
|
|
621
621
|
nodes {
|
|
622
|
-
${
|
|
622
|
+
${fe}
|
|
623
623
|
}
|
|
624
624
|
pageInfo {
|
|
625
625
|
endCursor
|
|
@@ -628,7 +628,7 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
|
|
|
628
628
|
}
|
|
629
629
|
}
|
|
630
630
|
}
|
|
631
|
-
`,variables:{owner:n,name:o,cursor:
|
|
631
|
+
`,variables:{owner:n,name:o,cursor:i,first:v}},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(ut))??[]}}};var es="https://gitlab.com/api/v4",ts="https://gitlab.com/api/graphql",Zt=/\/api\/v\d+$/,er=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.")},pt=(s,e)=>{let t=e.baseUrl||s.baseUrl;return t?(t=t.replace(/\/$/,""),er(t),t):es},rs=(s,e)=>{let t=e.baseUrl||s.baseUrl;return t?(t=t.replace(/\/$/,""),er(t),Zt.test(t)&&(t=t.replace(Zt,"")),`${t}/api/graphql`):ts},w=(s,e,t)=>{let r=f(t.token||s.token);return s.request({url:rs(s,t),method:"POST",headers:{...r,"Content-Type":"application/json"},body:JSON.stringify(e)})};var ht=s=>s.split("/").slice(0,-1).join("/"),ft=s=>s.split("/").at(-1)??"",ye=s=>({id:s.id.replace(K,""),graphQLId:s.id,namespace:ht(s.fullPath),name:ft(s.fullPath),webUrl:s.webUrl}),tr=s=>({id:s.id.replace(K,""),graphQLId:s.id,httpsUrl:s.httpUrlToRepo,namespace:ht(s.fullPath),name:ft(s.fullPath),sshUrl:s.sshUrlToRepo,webUrl:s.webUrl}),ss={assigned:"assignedMergeRequests",authored:"authoredMergeRequests",reviewRequested:"reviewRequestedMergeRequests"},ns={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"},os="gid://gitlab/User/",K="gid://gitlab/Project/",is="gid://gitlab/MergeRequest/",as="gid://gitlab/Issue/",us="gid://gitlab/ProjectLabel/",ls="gid://gitlab/Milestone/",ps="gid://gitlab/Ci::Build/",It=`
|
|
632
632
|
description
|
|
633
633
|
dueDate
|
|
634
634
|
id
|
|
@@ -637,7 +637,7 @@ startDate
|
|
|
637
637
|
state
|
|
638
638
|
title
|
|
639
639
|
webPath
|
|
640
|
-
`,
|
|
640
|
+
`,dt=`
|
|
641
641
|
id
|
|
642
642
|
fullPath
|
|
643
643
|
webUrl
|
|
@@ -646,25 +646,25 @@ sshUrlToRepo
|
|
|
646
646
|
repository {
|
|
647
647
|
rootRef
|
|
648
648
|
}
|
|
649
|
-
`,
|
|
649
|
+
`,B=`
|
|
650
650
|
id
|
|
651
651
|
name
|
|
652
652
|
username
|
|
653
653
|
publicEmail
|
|
654
654
|
avatarUrl
|
|
655
655
|
webUrl
|
|
656
|
-
`,
|
|
656
|
+
`,Rt=`
|
|
657
657
|
color
|
|
658
658
|
description
|
|
659
659
|
id
|
|
660
660
|
title
|
|
661
|
-
`,
|
|
661
|
+
`,ct=`
|
|
662
662
|
author {
|
|
663
|
-
${
|
|
663
|
+
${B}
|
|
664
664
|
}
|
|
665
665
|
assignees {
|
|
666
666
|
nodes {
|
|
667
|
-
${
|
|
667
|
+
${B}
|
|
668
668
|
}
|
|
669
669
|
}
|
|
670
670
|
closedAt
|
|
@@ -675,7 +675,7 @@ id
|
|
|
675
675
|
iid
|
|
676
676
|
labels {
|
|
677
677
|
nodes {
|
|
678
|
-
${
|
|
678
|
+
${Rt}
|
|
679
679
|
}
|
|
680
680
|
}
|
|
681
681
|
state
|
|
@@ -686,9 +686,9 @@ upvotes
|
|
|
686
686
|
userNotesCount
|
|
687
687
|
webUrl
|
|
688
688
|
milestone {
|
|
689
|
-
${
|
|
689
|
+
${It}
|
|
690
690
|
}
|
|
691
|
-
`,
|
|
691
|
+
`,ds=`
|
|
692
692
|
stages {
|
|
693
693
|
nodes {
|
|
694
694
|
jobs {
|
|
@@ -704,12 +704,12 @@ stages {
|
|
|
704
704
|
name
|
|
705
705
|
}
|
|
706
706
|
}
|
|
707
|
-
`,
|
|
707
|
+
`,rr=(s,e,t)=>`
|
|
708
708
|
id
|
|
709
709
|
state
|
|
710
710
|
approved
|
|
711
711
|
author {
|
|
712
|
-
${
|
|
712
|
+
${B}
|
|
713
713
|
}
|
|
714
714
|
diffRefs {
|
|
715
715
|
baseSha
|
|
@@ -734,12 +734,12 @@ targetBranch
|
|
|
734
734
|
sourceBranch
|
|
735
735
|
assignees {
|
|
736
736
|
nodes {
|
|
737
|
-
${
|
|
737
|
+
${B}
|
|
738
738
|
}
|
|
739
739
|
}
|
|
740
740
|
reviewers {
|
|
741
741
|
nodes {
|
|
742
|
-
${
|
|
742
|
+
${B}
|
|
743
743
|
mergeRequestInteraction {
|
|
744
744
|
approved
|
|
745
745
|
reviewState
|
|
@@ -749,19 +749,19 @@ reviewers {
|
|
|
749
749
|
mergeStatusEnum
|
|
750
750
|
labels {
|
|
751
751
|
nodes {
|
|
752
|
-
${
|
|
752
|
+
${Rt}
|
|
753
753
|
}
|
|
754
754
|
}
|
|
755
|
-
${
|
|
756
|
-
${
|
|
757
|
-
${
|
|
758
|
-
`,
|
|
755
|
+
${s?"project { id httpUrlToRepo fullPath sshUrlToRepo webUrl } sourceProject { id httpUrlToRepo fullPath sshUrlToRepo webUrl }":""}
|
|
756
|
+
${e?`milestone { ${It} }`:""}
|
|
757
|
+
${t?`headPipeline { ${ds} }`:""}
|
|
758
|
+
`,W=s=>`${s.namespace}/${s.name}`,cs=s=>`${s.namespace}/${s.name}`,gt=s=>{var e;return{id:s.id.replace(K,""),graphQLId:s.id,namespace:ht(s.fullPath),name:ft(s.fullPath),webUrl:s.webUrl,httpsUrl:s.httpUrlToRepo,sshUrl:s.sshUrlToRepo,defaultBranch:(e=s.repository)!=null&&e.rootRef?{name:s.repository.rootRef}:null,permission:null}},gs={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},j=(s,e)=>{let t=s.avatarUrl;return!e&&(t!=null&&t.startsWith("/"))&&(t=`https://gitlab.com${t}`),{id:s.id.replace(os,""),graphQLId:s.id,name:s.name,username:s.username,email:s.publicEmail??null,avatarUrl:t,url:s.webUrl}},yt=s=>({color:s.color,description:s.description,id:s.id.replace(us,""),graphQLId:s.id,name:s.title}),ms=(s,e)=>s?s==="FAILED"&&e?"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,sr=(s,e,t,r)=>{var o,i,a,u,l,p,d,c,g,m,I,P;let n=(o=s.reviewers)!=null&&o.nodes?s.reviewers.nodes.map(h=>{var b,y;return{reviewer:j(h,r),state:(b=h.mergeRequestInteraction)!=null&&b.approved?"APPROVED":((y=h.mergeRequestInteraction)==null?void 0:y.reviewState)==="REVIEWED"?"CHANGES_REQUESTED":"CHANGES_REQUESTED"}}):null;return{id:s.id.replace(is,""),graphQLId:s.id,title:s.title,number:parseInt(s.iid,10),state:gs[s.state],commentCount:s.userNotesCount||0,upvoteCount:s.upvotes,author:s.author?j(s.author,r):null,createdDate:new Date(s.createdAt),isDraft:s.draft,repository:{id:e.id,graphQLId:e.graphQLId,name:e.name,owner:{login:e.namespace},remoteInfo:e.httpsUrl&&e.sshUrl?{cloneUrlHTTPS:e.httpsUrl,cloneUrlSSH:e.sshUrl}:null},headRepository:t?{id:t.id,graphQLId:t.graphQLId,name:t.name,owner:{login:t.namespace},remoteInfo:{cloneUrlHTTPS:t.httpsUrl,cloneUrlSSH:t.sshUrl}}:null,headCommit:{buildStatuses:((u=(a=(i=s.headPipeline)==null?void 0:i.stages)==null?void 0:a.nodes)==null?void 0:u.flatMap(h=>{var b,y;return((y=(b=h.jobs)==null?void 0:b.nodes)==null?void 0:y.map($=>({completedAt:$.finishedAt?new Date($.finishedAt):null,description:null,name:$.name??null,state:ms($.status,$.allowFailure),stage:h.name??null,startedAt:new Date($.createdAt),url:`${e.webUrl}/-/jobs/${$.id.replace(ps,"")}`})))??[]}))??[]},baseRef:{name:s.targetBranch,oid:((l=s.diffRefs)==null?void 0:l.baseSha)??null},headRef:{name:s.sourceBranch,oid:((p=s.diffRefs)==null?void 0:p.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:(d=s.assignees)!=null&&d.nodes?s.assignees.nodes.map(h=>j(h,r)):null,reviews:n,reviewDecision:s.approved?"APPROVED":F(n),additions:((c=s.diffStatsSummary)==null?void 0:c.additions)||0,deletions:((g=s.diffStatsSummary)==null?void 0:g.deletions)||0,fileCount:((m=s.diffStatsSummary)==null?void 0:m.fileCount)||0,commitCount:s.commitCount||0,mergeableState:ns[s.mergeStatusEnum],milestone:s.milestone?bt(s.milestone,e.webUrl):null,labels:((P=(I=s.labels)==null?void 0:I.nodes)==null?void 0:P.map(yt))??[],permissions:null}},mt=(s,e,t)=>{var r,n;return{author:j(s.author,t),assignees:s.assignees.nodes.map(o=>j(o,t)),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(as,""),labels:((n=(r=s.labels)==null?void 0:r.nodes)==null?void 0:n.map(yt))??[],number:s.iid,repository:{id:e.id.replace(K,""),graphQLId:e.id,name:e.name,owner:{login:e.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?bt(s.milestone,e.webUrl):null}},bt=(s,e)=>({id:s.id.replace(ls,""),graphQLId:s.id,number:parseInt(s.iid,10),title:s.title,description:s.description,isOpen:s.state==="active",url:`${e}/-/${s.webPath.replace(/.+?\/-\//,"")}`,startDate:s.startDate?new Date(s.startDate):null,dueDate:s.dueDate?new Date(s.dueDate):null}),re=class extends k{getIsSelfHosted(e){return!!e.baseUrl||!!this.config.baseUrl}async getCurrentUser(e={},t={}){var o;let n=(o=(await w(this.config,{query:`
|
|
759
759
|
query getCurrentUser {
|
|
760
760
|
currentUser {
|
|
761
|
-
${
|
|
761
|
+
${B}
|
|
762
762
|
}
|
|
763
763
|
}
|
|
764
|
-
`},
|
|
764
|
+
`},t)).body.data)==null?void 0:o.currentUser;if(!n)throw new Error("Current user not found.");return{data:j(n,this.getIsSelfHosted(t))}}async getUserForCommit(e,t={}){var i,a,u,l;let r=W(e.repo),o=(l=(u=(a=(i=(await w(this.config,{query:`
|
|
765
765
|
query getUserForCommit($fullPath: ID!, $oid: String!) {
|
|
766
766
|
project(fullPath: $fullPath) {
|
|
767
767
|
repository {
|
|
@@ -775,21 +775,21 @@ query getUserForCommit($fullPath: ID!, $oid: String!) {
|
|
|
775
775
|
}
|
|
776
776
|
}
|
|
777
777
|
}
|
|
778
|
-
`,variables:{fullPath:
|
|
778
|
+
`,variables:{fullPath:r,oid:e.oid}},t)).body.data)==null?void 0:i.project)==null?void 0:a.repository)==null?void 0:u.tree)==null?void 0:l.lastCommit;if(!o)throw new Error("Commit not found.");return{data:{name:o.authorName,email:o.authorEmail,avatarUrl:o.authorGravatar}}}async getAccountForEmail(e,t={}){var o,i,a;let n=(a=(i=(o=(await w(this.config,{query:`
|
|
779
779
|
query getAccountForEmail($email: String!) {
|
|
780
780
|
users(search: $email) {
|
|
781
781
|
nodes {
|
|
782
|
-
${
|
|
782
|
+
${B}
|
|
783
783
|
}
|
|
784
784
|
}
|
|
785
785
|
}
|
|
786
|
-
`,variables:{email:
|
|
786
|
+
`,variables:{email:e.email}},t)).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:j(n,this.getIsSelfHosted(t))}}async getAccountForUsername(e,t={}){var o;let n=(o=(await w(this.config,{query:`
|
|
787
787
|
query getAccountForUsername($username: String!) {
|
|
788
788
|
user(username: $username) {
|
|
789
|
-
${
|
|
789
|
+
${B}
|
|
790
790
|
}
|
|
791
791
|
}
|
|
792
|
-
`,variables:{username:
|
|
792
|
+
`,variables:{username:e.username}},t)).body.data)==null?void 0:o.user;if(!n)throw new Error("User not found.");return{data:j(n,this.getIsSelfHosted(t))}}async getAccountsForRepo(e,t={}){var u,l,p,d,c,g,m;let{repo:{namespace:r,name:n},cursor:o}=e,i=await w(this.config,{query:`
|
|
793
793
|
query getAccountsForRepo(
|
|
794
794
|
$fullPath: ID!
|
|
795
795
|
$after: String
|
|
@@ -800,7 +800,7 @@ query getAccountsForRepo(
|
|
|
800
800
|
projectMembers(after: $after) {
|
|
801
801
|
nodes {
|
|
802
802
|
user {
|
|
803
|
-
${
|
|
803
|
+
${B}
|
|
804
804
|
}
|
|
805
805
|
}
|
|
806
806
|
pageInfo {
|
|
@@ -810,22 +810,22 @@ query getAccountsForRepo(
|
|
|
810
810
|
}
|
|
811
811
|
}
|
|
812
812
|
}
|
|
813
|
-
`,variables:{fullPath:`${
|
|
813
|
+
`,variables:{fullPath:`${r}/${n}`,after:o}},t),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(I=>I.user).filter(I=>I!==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(I=>j(I,this.getIsSelfHosted(t))))??[]}}async getRepo(e,t={}){var o;let r=W(e),n=await w(this.config,{query:`
|
|
814
814
|
query getRepo($fullPath: ID!) {
|
|
815
815
|
project(fullPath: $fullPath) {
|
|
816
|
-
${
|
|
816
|
+
${dt}
|
|
817
817
|
}
|
|
818
818
|
}
|
|
819
|
-
`,variables:{fullPath:
|
|
819
|
+
`,variables:{fullPath:r}},t);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);return{data:gt(n.body.data.project)}}async getRepos(e,t={}){let n=e.map(W).map((u,l)=>`
|
|
820
820
|
getRepo_${l}: project(fullPath: "${u}") {
|
|
821
|
-
${
|
|
821
|
+
${dt}
|
|
822
822
|
}
|
|
823
823
|
`).join(`
|
|
824
824
|
`),o=await w(this.config,{query:`
|
|
825
825
|
query batchGetRepos {
|
|
826
826
|
${n}
|
|
827
827
|
}
|
|
828
|
-
`},
|
|
828
|
+
`},t);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 getReposForCurrentUser(e,t={}){var o,i,a,u,l,p;let r=await w(this.config,{query:`
|
|
829
829
|
query getReposForCurrentUser($after: String) {
|
|
830
830
|
projects(membership: true first: 100 after: $after) {
|
|
831
831
|
pageInfo {
|
|
@@ -833,29 +833,29 @@ query getReposForCurrentUser($after: String) {
|
|
|
833
833
|
hasNextPage
|
|
834
834
|
}
|
|
835
835
|
nodes {
|
|
836
|
-
${
|
|
836
|
+
${dt}
|
|
837
837
|
}
|
|
838
838
|
}
|
|
839
839
|
}
|
|
840
|
-
`,variables:{after:
|
|
840
|
+
`,variables:{after:e.cursor}},t);if(!((o=r.body.data)!=null&&o.projects))throw new Error(((i=r.body.errors)==null?void 0:i[0].message)||r.statusText||"Unknown error");let n=((u=(a=r.body.data)==null?void 0:a.projects)==null?void 0:u.nodes)||[];return{pageInfo:(p=(l=r.body.data)==null?void 0:l.projects)==null?void 0:p.pageInfo,data:n.map(gt)}}async getRefs(e,t,r={}){var u;let n=W(t.repo),o=new URL(`${pt(this.config,r)}/projects/${encodeURIComponent(n)}/repository/${e}`);o.searchParams.set("page",((u=t.page)==null?void 0:u.toString())||"1"),o.searchParams.set("per_page",v.toString());let i=await this.config.request({url:o.toString(),headers:f(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(e,t={}){return this.getRefs("branches",e,t)}async getTags(e,t={}){return this.getRefs("tags",e,t)}async getBlame(e,t={}){let r=W(e.repo),n=new URL(`${pt(this.config,t)}/projects/${encodeURIComponent(r)}/repository/files/${encodeURIComponent(e.path)}/blame`);n.searchParams.set("ref",e.ref);let o=await this.config.request({url:n.toString(),headers:f(t.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(e,t={}){var i,a;let r=ss[e.association],n=await w(this.config,{query:`
|
|
841
841
|
query getPullRequestsForUser($username: String! $cursor: String) {
|
|
842
842
|
user(username: $username) {
|
|
843
|
-
${
|
|
843
|
+
${r}(state:opened first:100 after:$cursor) {
|
|
844
844
|
pageInfo {
|
|
845
845
|
endCursor
|
|
846
846
|
hasNextPage
|
|
847
847
|
}
|
|
848
848
|
nodes {
|
|
849
|
-
${
|
|
849
|
+
${rr(!0,!0,!0)}
|
|
850
850
|
}
|
|
851
851
|
}
|
|
852
852
|
}
|
|
853
853
|
}
|
|
854
|
-
`,variables:{username:
|
|
854
|
+
`,variables:{username:e.username,cursor:e.cursor}},t);if(!n.body.data)throw new Error(((i=n.body.errors)==null?void 0:i[0].message)||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:((a=o.nodes)==null?void 0:a.map(u=>sr(u,tr(u.project),tr(u.sourceProject),this.getIsSelfHosted(t))))||[]}}async getPullRequestsAssociatedWithUser(e,t={}){var c;let[r,n,o]=((c=e.cursor)==null?void 0:c.split(";"))||[void 0,void 0,void 0],[i,a,u]=await Promise.all([r==="null"?null:this.getPullRequestsForUser({username:e.username,association:"authored",cursor:r},t),n==="null"?null:this.getPullRequestsForUser({username:e.username,association:"assigned",cursor:n},t),o==="null"?null:this.getPullRequestsForUser({username:e.username,association:"reviewRequested",cursor:o},t)]),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(e){let{updatedBefore:t,isDraft:r,authorLogin:n,assigneeLogins:o,reviewRequestedLogin:i}=e||{},a={},u=[],l=[],p=(d,c,g)=>{u.push(`$${d}: ${g}`),l.push(`${d}: $${d}`),a[d]=c};return t&&p("updatedBefore",t,"Time"),n&&p("authorUsername",n,"String"),o&&p("assigneeUsername",o[0],"String"),r!=null&&p("draft",r,"Boolean"),i&&p("reviewerUsername",i,"String"),{variables:a,variableTypes:u,mergeRequestArguments:l}}async getPullRequestsForRepo(e,t={}){var I,P,h;let{cursor:r,repo:n}=e||{},o=W(n),{variables:i,variableTypes:a,mergeRequestArguments:u}=this.getVariablesForPullRequests(e),l={fullPath:o,...i},p=await w(this.config,{query:`
|
|
855
855
|
query getPullRequestsForRepo(
|
|
856
856
|
$fullPath: ID!
|
|
857
857
|
$after: String
|
|
858
|
-
${
|
|
858
|
+
${a.length?a.join(" "):""}
|
|
859
859
|
) {
|
|
860
860
|
project(
|
|
861
861
|
fullPath: $fullPath
|
|
@@ -875,19 +875,19 @@ query getPullRequestsForRepo(
|
|
|
875
875
|
hasNextPage
|
|
876
876
|
}
|
|
877
877
|
nodes {
|
|
878
|
-
${
|
|
878
|
+
${rr(!1,!0,!0)}
|
|
879
879
|
}
|
|
880
880
|
}
|
|
881
881
|
}
|
|
882
882
|
}
|
|
883
|
-
`,variables:{...l,after:
|
|
883
|
+
`,variables:{...l,after:r}},t),d=[],c=(I=p.body.data)==null?void 0:I.project,g=ye(c||{id:"",fullPath:"",webUrl:""});return(((P=c==null?void 0:c.mergeRequests)==null?void 0:P.nodes)||[]).forEach(b=>{d.push(sr(b,g,null,this.getIsSelfHosted(t)))}),{pageInfo:(h=c==null?void 0:c.mergeRequests)==null?void 0:h.pageInfo,data:d}}async getPullRequestsForRepos(e,t={}){let{repos:r,assigneeLogins:n,updatedBefore:o,authorLogin:i,isDraft:a,reviewRequestedLogin:u}=e;return{data:(await Promise.all(r.map(p=>this.getPullRequestsForRepo({repo:p,assigneeLogins:n,updatedBefore:o,authorLogin:i,isDraft:a,reviewRequestedLogin:u},t)))).flatMap(p=>p.data)}}async closePullRequest(e,t={}){var a,u,l;let{pullRequest:r}=e,n=`mutation ClosePullRequest($fullPath: ID!, $pullRequestId: String!) {
|
|
884
884
|
mergeRequestUpdate(input: { projectPath: $fullPath, iid: $pullRequestId, state: CLOSED }) {
|
|
885
885
|
errors,
|
|
886
886
|
mergeRequest {
|
|
887
887
|
id
|
|
888
888
|
}
|
|
889
889
|
}
|
|
890
|
-
}`,
|
|
890
|
+
}`,i=(a=(await w(this.config,{query:n,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,pullRequestId:r.number.toString()}},t)).body.data)==null?void 0:a.mergeRequestUpdate;if(!((u=i==null?void 0:i.mergeRequest)!=null&&u.id)||((l=i==null?void 0:i.errors)==null?void 0:l.length)!==0)throw new Error("Could not close pull request")}async mergePullRequest(e,t={}){var u,l,p,d;let{pullRequest:r,mergeStrategy:n}=e;if(!((u=r.headRef)!=null&&u.oid))throw new Error('GitLab requires "headRef.oid" for this function.');let o=`mutation MergePullRequest(
|
|
891
891
|
$fullPath: ID!,
|
|
892
892
|
$pullRequestId: String!,
|
|
893
893
|
$expectedSourceSha: String!,
|
|
@@ -904,63 +904,63 @@ query getPullRequestsForRepo(
|
|
|
904
904
|
id
|
|
905
905
|
}
|
|
906
906
|
}
|
|
907
|
-
}`,
|
|
907
|
+
}`,a=(l=(await w(this.config,{query:o,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,pullRequestId:r.number.toString(),expectedSourceSha:r.headRef.oid,squash:n==="SQUASH"}},t)).body.data)==null?void 0:l.mergeRequestAccept;if(!((p=a==null?void 0:a.mergeRequest)!=null&&p.id)||((d=a==null?void 0:a.errors)==null?void 0:d.length)!==0)throw new Error("Could not merge pull request")}async setPullRequestMilestone(e,t={}){var u,l,p;let{pullRequest:r,milestone:n}=e;if(!r.graphQLId)throw new Error('GitHub requires "graphQLId" for this function.');let o=`mutation SetPullRequestMilestone($fullPath: ID!, $pullRequestId: String!, $milestoneGraphQLId: MilestoneID) {
|
|
908
908
|
mergeRequestSetMilestone(input: { projectPath: $fullPath, iid: $pullRequestId, milestoneId: $milestoneGraphQLId }) {
|
|
909
909
|
errors,
|
|
910
910
|
mergeRequest {
|
|
911
911
|
id
|
|
912
912
|
}
|
|
913
913
|
}
|
|
914
|
-
}`,
|
|
914
|
+
}`,i=await w(this.config,{query:o,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,pullRequestId:r.number.toString(),milestoneGraphQLId:n==null?void 0:n.graphQLId}},t),a=(u=i.body.data)==null?void 0:u.mergeRequestSetMilestone;if(!((l=a==null?void 0:a.mergeRequest)!=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 pull request")}async setPullRequestAsDraft(e,t={}){var u,l,p;let{pullRequest:r,isDraft:n}=e,o=`mutation MergeRequestSetDraft($fullPath: ID!, $pullRequestId: String!, $isDraft: Boolean!) {
|
|
915
915
|
mergeRequestSetDraft(input: { projectPath: $fullPath, iid: $pullRequestId, draft: $isDraft }) {
|
|
916
916
|
errors,
|
|
917
917
|
mergeRequest {
|
|
918
918
|
id
|
|
919
919
|
}
|
|
920
920
|
}
|
|
921
|
-
}`,
|
|
921
|
+
}`,a=(u=(await w(this.config,{query:o,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,pullRequestId:r.number.toString(),isDraft:n}},t)).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(e,t={}){var l,p,d;let{pullRequest:r,reviewers:n}=e,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!]!) {
|
|
922
922
|
mergeRequestSetReviewers(input: { projectPath: $fullPath, iid: $pullRequestId, reviewerUsernames: $reviewerUsernames }) {
|
|
923
923
|
errors,
|
|
924
924
|
mergeRequest {
|
|
925
925
|
id
|
|
926
926
|
}
|
|
927
927
|
}
|
|
928
|
-
}`,u=(l=(await w(this.config,{query:
|
|
928
|
+
}`,u=(l=(await w(this.config,{query:i,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,pullRequestId:r.number.toString(),reviewerUsernames:o}},t)).body.data)==null?void 0:l.mergeRequestSetReviewers;if(!((p=u==null?void 0:u.mergeRequest)!=null&&p.id)||((d=u==null?void 0:u.errors)==null?void 0:d.length)!==0)throw new Error("Could not set pull request reviewers")}async reRequestPullRequestReview(e,t={}){var u,l,p;let{pullRequest:r,reviewer:n}=e;if(!n.graphQLId)throw new Error('GitLab requires reviwer "graphQLId" for this function.');let o=`mutation MergeRequestReviewerRereview($fullPath: ID!, $pullRequestId: String!, $reviewerUserId: UserID!) {
|
|
929
929
|
mergeRequestReviewerRereview(input: { projectPath: $fullPath, iid: $pullRequestId, userId: $reviewerUserId }) {
|
|
930
930
|
errors,
|
|
931
931
|
mergeRequest {
|
|
932
932
|
id
|
|
933
933
|
}
|
|
934
934
|
}
|
|
935
|
-
}`,
|
|
935
|
+
}`,a=(u=(await w(this.config,{query:o,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,pullRequestId:r.number.toString(),reviewerUserId:n.graphQLId}},t)).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(e,t={}){let{pullRequest:r,reviewers:n}=e,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},t)))}async setPullRequestAssignees(e,t={}){var l,p,d;let{pullRequest:r,assignees:n}=e,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!]!) {
|
|
936
936
|
mergeRequestSetAssignees(input: { projectPath: $fullPath, iid: $pullRequestId, assigneeUsernames: $assigneeUsernames }) {
|
|
937
937
|
errors,
|
|
938
938
|
mergeRequest {
|
|
939
939
|
id
|
|
940
940
|
}
|
|
941
941
|
}
|
|
942
|
-
}`,u=(l=(await w(this.config,{query:
|
|
942
|
+
}`,u=(l=(await w(this.config,{query:i,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,pullRequestId:r.number.toString(),assigneeUsernames:o}},t)).body.data)==null?void 0:l.mergeRequestSetAssignees;if(!((p=u==null?void 0:u.mergeRequest)!=null&&p.id)||((d=u==null?void 0:u.errors)==null?void 0:d.length)!==0)throw new Error("Could not set pull request assignees")}async setPullRequestLabels(e,t={}){var u,l,p;let{pullRequest:r,labels:n}=e,o=n.map(d=>{if(!d.graphQLId)throw new Error('GitLab requires "graphQLId" for labels in this function.');return d.graphQLId}),i=`mutation SetPullRequestLabels($fullPath: ID!, $pullRequestId: String!, $labelGraphQLIds: [LabelID!]!) {
|
|
943
943
|
mergeRequestSetLabels(input: { projectPath: $fullPath, iid: $pullRequestId, labelIds: $labelGraphQLIds }) {
|
|
944
944
|
mergeRequest {
|
|
945
945
|
id
|
|
946
946
|
}
|
|
947
947
|
}
|
|
948
|
-
}`;if(!((p=(l=(u=(await w(this.config,{query:
|
|
948
|
+
}`;if(!((p=(l=(u=(await w(this.config,{query:i,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,pullRequestId:r.number.toString(),labelGraphQLIds:o}},t)).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(e,t={}){var o,i,a;let r=cs(e),n=await w(this.config,{query:`
|
|
949
949
|
query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
|
|
950
950
|
project(fullPath: $projectId) {
|
|
951
951
|
id
|
|
952
952
|
fullPath
|
|
953
953
|
webUrl
|
|
954
954
|
issue(iid: $issueNumber) {
|
|
955
|
-
${
|
|
955
|
+
${ct}
|
|
956
956
|
}
|
|
957
957
|
}
|
|
958
958
|
}
|
|
959
|
-
`,variables:{issueNumber:
|
|
959
|
+
`,variables:{issueNumber:e.number,projectId:r}},t);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 ${e.number} not found`);return{data:mt(n.body.data.project.issue,ye(n.body.data.project),this.getIsSelfHosted(t))}}getVariablesForIssues(e){let{updatedBefore:t,authorLogin:r,assigneeLogins:n}=e||{},o={},i=[],a=[],u=(l,p,d)=>{i.push(`$${l}: ${d}`),a.push(`${l}: $${l}`),o[l]=p};return t&&u("updatedBefore",t,"Time"),r&&u("authorUsername",r,"String"),n&&u("assigneeUsername",n[0],"String"),{variables:o,variableTypes:i,issueArguments:a}}async getIssuesForRepo(e,t={}){var P,h,b;let{cursor:r,repo:n}=e||{},o=W(n),{variables:i,variableTypes:a,issueArguments:u}=this.getVariablesForIssues(e),l={fullPath:o,...i},p=`
|
|
960
960
|
query GetIssuesFromProject(
|
|
961
961
|
$fullPath: ID!
|
|
962
962
|
$after: String
|
|
963
|
-
${
|
|
963
|
+
${a.length?a.join(" "):""}
|
|
964
964
|
) {
|
|
965
965
|
project(
|
|
966
966
|
fullPath: $fullPath
|
|
@@ -976,7 +976,7 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
|
|
|
976
976
|
${u.length?u.join(" "):""}
|
|
977
977
|
) {
|
|
978
978
|
nodes {
|
|
979
|
-
${
|
|
979
|
+
${ct}
|
|
980
980
|
}
|
|
981
981
|
pageInfo {
|
|
982
982
|
endCursor
|
|
@@ -984,11 +984,11 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
|
|
|
984
984
|
}
|
|
985
985
|
}
|
|
986
986
|
}
|
|
987
|
-
}`,d=await w(this.config,{query:p,variables:{...l,after:
|
|
987
|
+
}`,d=await w(this.config,{query:p,variables:{...l,after:r}},t),c=[],g=(P=d.body.data)==null?void 0:P.project,m=ye(g||{id:"",fullPath:"",webUrl:""});return(((h=g==null?void 0:g.issues)==null?void 0:h.nodes)||[]).forEach(y=>{c.push(mt(y,m,this.getIsSelfHosted(t)))}),{pageInfo:((b=g==null?void 0:g.issues)==null?void 0:b.pageInfo)??{endCursor:null,hasNextPage:!1},data:c.sort((y,$)=>(y.updatedDate||y.createdDate).getTime()-($.updatedDate||$.createdDate).getTime())}}async getIssuesForRepos(e,t={}){var g,m,I,P,h;let{cursor:r}=e||{},n=e.repoIds.map(b=>b.toString().startsWith(K)?b:`${K}${b}`),{variables:o,variableTypes:i,mergeRequestArguments:a}=this.getVariablesForPullRequests(e),u={projectIds:n,...o},l=`
|
|
988
988
|
query GetIssuesFromProject(
|
|
989
989
|
$projectIds: [ID!]
|
|
990
990
|
$after: String
|
|
991
|
-
${
|
|
991
|
+
${i.length?i.join(" "):""}
|
|
992
992
|
) {
|
|
993
993
|
projects(
|
|
994
994
|
ids: $projectIds
|
|
@@ -1006,27 +1006,27 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
|
|
|
1006
1006
|
first: 100
|
|
1007
1007
|
state: opened
|
|
1008
1008
|
sort: UPDATED_DESC
|
|
1009
|
-
${
|
|
1009
|
+
${a.length?a.join(" "):""}
|
|
1010
1010
|
) {
|
|
1011
1011
|
nodes {
|
|
1012
|
-
${
|
|
1012
|
+
${ct}
|
|
1013
1013
|
}
|
|
1014
1014
|
}
|
|
1015
1015
|
}
|
|
1016
1016
|
}
|
|
1017
|
-
}`,p=await w(this.config,{query:l,variables:{...u,after:
|
|
1017
|
+
}`,p=await w(this.config,{query:l,variables:{...u,after:r}},t),d=[];return(((m=(g=p.body.data)==null?void 0:g.projects)==null?void 0:m.nodes)||[]).forEach(b=>{var kt;let y=ye(b);(((kt=b.issues)==null?void 0:kt.nodes)||[]).forEach(Ir=>d.push(mt(Ir,y,this.getIsSelfHosted(t))))}),{pageInfo:((h=(P=(I=p.body)==null?void 0:I.data)==null?void 0:P.projects)==null?void 0:h.pageInfo)??{endCursor:null,hasNextPage:!1},data:d.sort((b,y)=>(b.updatedDate||b.createdDate).getTime()-(y.updatedDate||y.createdDate).getTime())}}async setIssueState(e,t={}){var a,u,l;let{issue:r,state:n}=e;if(!r.repository)throw new Error('GitLab requires "repository" for this function.');let o=`mutation SetIssueState($fullPath: ID!, $issueId: String!, $status: IssueStateEvent!) {
|
|
1018
1018
|
updateIssue(input: { projectPath: $fullPath, iid: $issueId, stateEvent: $status }) {
|
|
1019
1019
|
issue {
|
|
1020
1020
|
id
|
|
1021
1021
|
}
|
|
1022
1022
|
}
|
|
1023
|
-
}`;if(!((l=(u=(
|
|
1023
|
+
}`;if(!((l=(u=(a=(await w(this.config,{query:o,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,issueId:r.number,status:n==="OPEN"?"REOPEN":"CLOSE"}},t)).body.data)==null?void 0:a.updateIssue)==null?void 0:u.issue)!=null&&l.id))throw new Error("Could not set issue status")}async closeIssue(e,t={}){await this.setIssueState({...e,state:"CLOSED"},t)}async reOpenIssue(e,t={}){await this.setIssueState({...e,state:"OPEN"},t)}async setIssueLabels(e,t={}){var u,l,p;let{issue:r,labels:n}=e;if(!r.repository)throw new Error('GitLab requires a "repository" for this function.');let o=n.map(d=>{if(!d.graphQLId)throw new Error('GitLab requires label "graphQLId" for this function.');return d.graphQLId}),i=`mutation SetIssueLabels($fullPath: ID!, $issueId: String!, $labelGraphQLIds: [ID!]) {
|
|
1024
1024
|
updateIssue(input: { projectPath: $fullPath, iid: $issueId, labelIds: $labelGraphQLIds }) {
|
|
1025
1025
|
issue {
|
|
1026
1026
|
id
|
|
1027
1027
|
}
|
|
1028
1028
|
}
|
|
1029
|
-
}`;if(!((p=(l=(u=(await w(this.config,{query:
|
|
1029
|
+
}`;if(!((p=(l=(u=(await w(this.config,{query:i,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,issueId:r.number,labelGraphQLIds:o}},t)).body.data)==null?void 0:u.updateIssue)==null?void 0:l.issue)!=null&&p.id))throw new Error("Could not set issue labels")}async setIssueMilestone(e,t={}){var u,l,p;let{issue:r,milestone:n}=e;if(!r.repository)throw new Error('GitLab requires "repository" for this function.');let o=`mutation SetIssueMilestone($fullPath: ID!, $issueId: String!, $milestoneId: ID) {
|
|
1030
1030
|
updateIssue(input: { projectPath: $fullPath, iid: $issueId, milestoneId: $milestoneId }) {
|
|
1031
1031
|
errors
|
|
1032
1032
|
issue {
|
|
@@ -1036,14 +1036,14 @@ query GetSingleIssue($projectId: ID!, $issueNumber: String!) {
|
|
|
1036
1036
|
}
|
|
1037
1037
|
}
|
|
1038
1038
|
}
|
|
1039
|
-
}`,
|
|
1039
|
+
}`,i=await w(this.config,{query:o,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,issueId:r.number,milestoneId:(n==null?void 0:n.id)??null}},t),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(e,t={}){var l,p,d;let{issue:r,assignees:n}=e;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!]!) {
|
|
1040
1040
|
issueSetAssignees(input: { projectPath: $fullPath, iid: $issueId, assigneeUsernames: $assigneeUsernames }) {
|
|
1041
1041
|
errors,
|
|
1042
1042
|
issue {
|
|
1043
1043
|
id
|
|
1044
1044
|
}
|
|
1045
1045
|
}
|
|
1046
|
-
}`,u=(l=(await w(this.config,{query:
|
|
1046
|
+
}`,u=(l=(await w(this.config,{query:i,variables:{fullPath:`${r.repository.owner.login}/${r.repository.name}`,issueId:r.number,assigneeUsernames:o}},t)).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(e,t={}){var a,u,l,p,d,c,g;let{repo:{namespace:r,name:n},cursor:o}=e,i=await w(this.config,{query:`
|
|
1047
1047
|
query getLabelsForRepo(
|
|
1048
1048
|
$fullPath: ID!
|
|
1049
1049
|
$after: String
|
|
@@ -1054,7 +1054,7 @@ query getLabelsForRepo(
|
|
|
1054
1054
|
webUrl
|
|
1055
1055
|
milestones(after: $after) {
|
|
1056
1056
|
nodes {
|
|
1057
|
-
${
|
|
1057
|
+
${It}
|
|
1058
1058
|
}
|
|
1059
1059
|
pageInfo {
|
|
1060
1060
|
endCursor
|
|
@@ -1063,7 +1063,7 @@ query getLabelsForRepo(
|
|
|
1063
1063
|
}
|
|
1064
1064
|
}
|
|
1065
1065
|
}
|
|
1066
|
-
`,variables:{fullPath:`${
|
|
1066
|
+
`,variables:{fullPath:`${r}/${n}`,after:o}},t);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 I,P;return bt(m,((P=(I=i.body.data)==null?void 0:I.project)==null?void 0:P.webUrl)||"")}))??[]}}async getLabelsForRepo(e,t={}){var a,u,l,p,d,c,g;let{repo:{namespace:r,name:n},cursor:o}=e,i=await w(this.config,{query:`
|
|
1067
1067
|
query getLabelsForRepo(
|
|
1068
1068
|
$fullPath: ID!
|
|
1069
1069
|
$after: String
|
|
@@ -1073,7 +1073,7 @@ query getLabelsForRepo(
|
|
|
1073
1073
|
) {
|
|
1074
1074
|
labels(after: $after) {
|
|
1075
1075
|
nodes {
|
|
1076
|
-
${
|
|
1076
|
+
${Rt}
|
|
1077
1077
|
}
|
|
1078
1078
|
pageInfo {
|
|
1079
1079
|
endCursor
|
|
@@ -1082,5 +1082,5 @@ query getLabelsForRepo(
|
|
|
1082
1082
|
}
|
|
1083
1083
|
}
|
|
1084
1084
|
}
|
|
1085
|
-
`,variables:{fullPath:`${
|
|
1086
|
-
OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUser())`,l=(await r.request({url:`${z(r,t,o)}/rest/api/2/search?jql=${i}&startAt=${a}&maxResults=${Re}&fields=${at.join(",")}&expand=transitions`,headers:f(t.token||r.token)})).body.issues.map(d=>it(d,e,o)),p=l.length==Re;return{data:l,pageInfo:{hasNextPage:p,nextPage:p?a+l.length:null}}},we=async(r,s,e,t={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:a,page:i,project:u,resourceId:l}=s||{},p=i??0,d=[`project = "${u}"`,"statusCategory != Done"];o&&d.push(`creator in ("${o}")`),n&&n.length!==0&&d.push(`assignee in ("${n.join('", "')}")`),a&&d.push(`comment ~ "${a}"`);let g=(await r.request({url:`${z(r,t,l)}/rest/api/2/search?jql=${d.join(" AND ")}&startAt=${p}&maxResults=${Re}&fields=${at.join(",")}&expand=transitions`,headers:f(t.token||r.token)})).body.issues.map(R=>it(R,e,l)),m=g.length==Re;return{data:g,pageInfo:{hasNextPage:m,nextPage:m?p+g.length:null}}},Pe=async(r,s,e={})=>{let{issue:t,labels:n}=s;if(!t.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{labels:n.map(a=>a.name)}};await r.request({method:"PUT",url:`${z(r,e,t.project.resourceId??void 0)}/rest/api/2/issue/${t.id}`,body:JSON.stringify(o),headers:{...f(e.token||r.token),"Content-Type":"application/json"}})},qe=async(r,s,e={})=>{let{issue:t,components:n}=s;if(!t.project)throw new Error('Jira requires a "project" for this function.');let o={fields:{components:n.map(a=>({id:a.id}))}};await r.request({method:"PUT",url:`${z(r,e,t.project.resourceId??void 0)}/rest/api/2/issue/${t.id}`,body:JSON.stringify(o),headers:{...f(e.token||r.token),"Content-Type":"application/json"}})},Se=async(r,s,e={})=>{let{issue:t,status:n}=s;if(!t.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 r.request({method:"POST",url:`${z(r,e,t.project.resourceId??void 0)}/rest/api/2/issue/${t.id}/transitions`,body:JSON.stringify(o),headers:{...f(e.token||r.token),"Content-Type":"application/json"}})},ve=async(r,s,e={})=>{let{resourceId:t,projectIdOrKey:n}=s,o=new URL(`${z(r,e,t)}/rest/api/2/project/${n}/components`);return{data:(await r.request({url:o.toString(),headers:f(e.token||r.token)})).body}};var ee="https://api.atlassian.com/ex/jira",ut=100,te=class extends U{constructor(){super(...arguments);this._resourceUrlCache={}}async getResourceUrl(e,t={}){var a;let n=t.token||this.config.token;if(!n)return null;let o=this._resourceUrlCache[n];return o?o[e.resourceId]??null:(await this.getJiraResourcesForCurrentUser(t),((a=this._resourceUrlCache[n])==null?void 0:a[e.resourceId])??null)}async getCurrentUserForResource(e,t={}){let n=await this.getResourceUrl({resourceId:e.resourceId},t),o=await this.config.request({url:`${t.baseUrl||ee}/${e.resourceId}/rest/api/2/myself`,headers:f(t.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 t=await this.config.request({url:`${e.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:f(e.token||this.config.token)}),n=e.token||this.config.token,o=n?this._resourceUrlCache[n]||{}:void 0,a=t.body.map(i=>(o&&(o[i.id]=i.url),{avatarUrl:i.avatarUrl,id:i.id,name:i.name,url:i.url}));return n&&(this._resourceUrlCache[n]=o),{data:a}}async getJiraProjectsForResource(e,t={}){let n=new URL(`${t.baseUrl||ee}/${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:f(t.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(a=>({id:a.id,key:a.key,name:a.name,resourceId:e.resourceId}))}}async getJiraProjectsForResources(e,t={}){let n=[];return await Promise.all(e.resourceIds.map(async o=>{let a=await this.getJiraProjectsForResource({resourceId:o},t);n.push(...a.data)})),{data:n}}async getAccountsForJiraProject(e,t={}){let{resourceId:n,projectKey:o,cursor:a}=e,i=await this.getResourceUrl({resourceId:n},t),u=new URL(`${t.baseUrl||ee}/${n}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",ut.toString()),a&&u.searchParams.set("startAt",a),u.searchParams.set("project",o);let l=await this.config.request({url:u.toString(),headers:f(t.token||this.config.token)});return{pageInfo:{hasNextPage:l.body.length!==0,endCursor:((a?parseInt(a):0)+l.body.length).toString()},data:l.body.filter(p=>p.accountType!=="app"&&p.active).map(p=>Ie(p,i,!1))}}async getComponentsForJiraProject(e,t={}){return await ve(this.config,e,t)}async getIssue(e,t={}){let n=await this.getResourceUrl({resourceId:e.resourceId},t);return await be(this.config,e,n,t)}async getIssuesForProject(e,t={}){let n=await this.getResourceUrl({resourceId:e.resourceId},t);return await we(this.config,e,n,t)}async getIssuesForResourceForCurrentUser(e,t={}){let n=await this.getResourceUrl({resourceId:e.resourceId},t);return await ye(this.config,e,n,t)}async setIssueStatus(e,t={}){await Se(this.config,e,t)}async setIssueAssignee(e,t={}){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 a={accountId:o==null?void 0:o.id};await this.config.request({method:"PUT",url:`${t.baseUrl||ee}/${n.project.resourceId}/rest/api/2/issue/${n.id}/assignee`,body:JSON.stringify(a),headers:{...f(t.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(e,t={}){await qe(this.config,e,t)}async setIssueLabels(e,t={}){await Pe(this.config,e,t)}async getLabelsForResource(e,t={}){let{resourceId:n,cursor:o}=e,a=new URL(`${t.baseUrl||ee}/${n}/rest/api/2/label`);a.searchParams.set("maxResults",ut.toString()),o&&a.searchParams.set("startAt",o);let i=await this.config.request({url:a.toString(),headers:f(t.token||this.config.token)});return{pageInfo:{hasNextPage:!i.body.isLast,endCursor:(i.body.startAt+i.body.values.length).toString()},data:i.body.values.map(u=>({color:null,description:null,id:null,name:u}))}}};var se=class extends A{async getCurrentUser(s={}){let e=await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/myself`,headers:f((s==null?void 0:s.token)||this.config.token)});return{data:{name:e.body.displayName,email:e.body.emailAddress,avatarUrl:e.body.avatarUrls["48x48"],id:e.body.key,username:e.body.displayName,url:null}}}async getJiraProjects(s={}){return{data:(await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/project`,headers:f((s==null?void 0:s.token)||this.config.token)})).body.map(t=>({id:t.id,name:t.name}))}}async getIssue(s,e={}){if(!e.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await be(this.config,s,e.baseUrl,e)}async getIssuesForProject(s,e={}){if(!e.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await we(this.config,s,e.baseUrl,e)}async getIssuesForResourceForCurrentUser(s,e={}){if(!e.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await ye(this.config,s,e.baseUrl,e)}async setIssueStatus(s,e={}){await Se(this.config,s,e)}async setIssueLabels(s,e={}){await Pe(this.config,s,e)}async setIssueComponents(s,e={}){await qe(this.config,s,e)}async getLabels(s={}){return{data:(await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/jql/autocompletedata/suggestions?fieldName=labels`,headers:f(s.token||this.config.token)})).body.results.map(({displayName:t})=>({color:null,description:null,id:null,name:t}))}}async getComponentsForJiraProject(s,e={}){return await ve(this.config,s,e)}};var Q="https://api.trello.com",or=1e3,ar=(r,s)=>{let e=new Date(1e3*parseInt(r.id.substring(0,8),16));return{id:r.id,commentCount:r.badges.comments,number:r.idShort.toString(),title:r.name,url:r.url,closedDate:null,createdDate:new Date(e.toISOString()),author:null,updatedDate:new Date(r.dateLastActivity),assignees:r.idMembers.map(t=>({id:t,username:null,name:null,email:null,avatarUrl:null,url:null})),description:null,state:s[r.idList??""]?{id:r.idList,name:s[r.idList].name,color:null}:null,type:null,repository:null,upvoteCount:r.badges.votes,labels:r.labels.map(t=>({color:t.color,description:null,id:t.id,name:t.name}))}},re=class extends U{async getCurrentUser(s,e={}){let t=await this.config.request({url:`${e.baseUrl||Q}/1/members/me?key=${s.appKey}&token=${e.token||this.config.token}`,headers:f(e.token||this.config.token)});return{data:{name:t.body.fullName,email:t.body.email,avatarUrl:t.body.avatarHash?`https://trello-members.s3.amazonaws.com/${t.body.id}/${t.body.avatarHash}/50.png`:null,id:t.body.id,username:t.body.username,url:t.body.url}}}async getBoardsForCurrentUser(s,e={}){return{data:(await this.config.request({url:`${e.baseUrl||Q}/1/members/me/boards?fields=name&key=${s.appKey}&token=${e.token||this.config.token}&filter=open`,headers:f(e.token||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getListsForTrelloBoard(s,e={}){let{appKey:t,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||Q}/1/boards/${n}/lists?key=${t}&token=${e.token||this.config.token}`,headers:f(e.token||this.config.token)})).body}}async getAccountsForTrelloBoard(s,e={}){let{appKey:t,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||Q}/1/boards/${n}/members?key=${t}&token=${e.token||this.config.token}`,headers:f(e.token||this.config.token)})).body.map(a=>({id:a.id,name:a.fullName,username:a.username,email:null,avatarUrl:null,url:null}))}}async getIssuesForBoard(s,e={}){let t=["-is:archived","sort:edited"],{appKey:n,boardId:o,filterText:a,assigneeLogins:i,trelloBoardListsById:u}=s||{};i&&t.push("@me");let l=`${a?`${a}`:""}${t.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${e.baseUrl||Q}/1/search?key=${n}&query=${l}&cards_limit=${or}&token=${e.token||this.config.token}`,headers:f(e.token||this.config.token)})).body.cards.map(d=>ar(d,u||{}))}}async updateIssue(s,e,t,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||Q}/1/cards/${e.id}?key=${s}&token=${n.token||this.config.token}&${t}`,headers:f(n.token||this.config.token)})}async setIssueStatus(s,e={}){let{appKey:t,issue:n,status:o}=s;if(!o.id)throw new Error('Trello requires a status "id" for this function.');let a=`idList=${o.id}`;if(!(await this.updateIssue(t,n,a,e)).body.id)throw new Error("Could not set issue status")}async setIssueAssignees(s,e={}){let{appKey:t,issue:n,assignees:o}=s,a=o.map(l=>l.id),i=`idMembers=${encodeURIComponent(a.join(","))}`;if(!(await this.updateIssue(t,n,i,e)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(s,e={}){let{appKey:t,issue:n,labels:o}=s,a=o.map(u=>u.id).join(",");if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||Q}/1/cards/${n.id}?key=${t}&token=${e.token||this.config.token}&idLabels=${encodeURIComponent(a)}`,headers:f(e.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(s,e={}){let{appKey:t,issue:n,archived:o}=s;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||Q}/1/cards/${n.id}?key=${t}&token=${e.token||this.config.token}&closed=${o}`,headers:f(e.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async archiveIssue(s,e={}){await this.setIssueArchived({...s,archived:!0},e)}async unArchiveIssue(s,e={}){await this.setIssueArchived({...s,archived:!1},e)}async getLabelsForBoard(s,e={}){let{appKey:t,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||Q}/1/boards/${n}/labels?key=${t}&token=${e.token||this.config.token}`,headers:f(e.token||this.config.token)})).body.map(a=>({color:a.color,description:null,id:a.id,name:a.name}))}}};var Ee={};O(Ee,{getIssueUniqueId:()=>ir,getPullRequestUniqueId:()=>ur});var ir=(r,s,e,t="")=>{let n=[];return n.push(t),n.push(r),n.push(s),n.push(e),JSON.stringify(n)},ur=(r,s,e,t,n="")=>{let o=[];return o.push(n),o.push(r),o.push(s),o.push(e),o.push(t),JSON.stringify(o)};var Ce={};O(Ce,{getIssueUniqueId:()=>lr,getPullRequestUniqueId:()=>pr});var lr=(r,s)=>JSON.stringify(["",r,s]),pr=(r,s)=>JSON.stringify(["",r,s]);var De={};O(De,{getIssueUniqueId:()=>dr,getPullRequestUniqueId:()=>cr});var dr=(r,s,e)=>JSON.stringify([e,r,s]),cr=(r,s,e)=>JSON.stringify([e,r,s]);var Ue={};O(Ue,{CHANGES_REQUESTED_ACTION_CATEGORY:()=>Jt,CHANGES_REQUESTED_BUCKET_ID:()=>ht,CONFLICTS_ACTION_CATEGORY:()=>Ht,CONFLICTS_BUCKET_ID:()=>gt,DRAFT_ACTION_CATEGORY:()=>Xt,DRAFT_BUCKET_ID:()=>It,FAILING_CI_ACTION_CATEGORY:()=>zt,FAILING_CI_BUCKET_ID:()=>ct,NEEDS_MY_REVIEW_ACTION_CATEGORY:()=>Wt,NEEDS_MY_REVIEW_BUCKET_ID:()=>mt,OTHER_ACTION_CATEGORY:()=>Yt,OTHER_BUCKET_ID:()=>bt,PINNED_BUCKET_ID:()=>lt,READY_TO_MERGE_ACTION_CATEGORY:()=>jt,READY_TO_MERGE_BUCKET_ID:()=>pt,REVIEWER_COMMENTED_ACTION_CATEGORY:()=>Kt,REVIEWER_COMMENTED_BUCKET_ID:()=>ft,SNOOZED_BUCKET_ID:()=>yt,UNASSIGNED_REVIEWERS_ACTION_CATEGORY:()=>Mt,UNASSIGNED_REVIEWERS_BUCKET_ID:()=>dt,WAITING_FOR_REVIEW_ACTION_CATEGORY:()=>Vt,WAITING_FOR_REVIEW_BUCKET_ID:()=>Rt,getActionablePullRequests:()=>Zt,groupPullRequestsIntoBuckets:()=>gr});var C=(r,s,e,t)=>({id:r,faIconName:e,name:s,priority:t,pullRequests:[]}),lt="pinned",pt="readyToMerge",dt="unassignedReviewers",ct="failingCI",gt="conflicts",mt="needsMyReview",ht="changesRequested",ft="reviewerCommented",Rt="waitingForReview",It="draft",bt="other",yt="snoozed",jt="readyToMerge",Mt="unassignedReviewers",zt="failingCI",Ht="conflicts",Wt="needsMyReview",Jt="changesRequested",Kt="reviewerCommented",Vt="waitingForReview",Xt="draft",Yt="other",Zt=(r,s,e)=>r.map(t=>{var i,u,l,p,d,c,g,m,R,P,h,y;let o={...t,...{suggestedActionCategory:Yt,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,commentReviewCount:0,approvalReviewCount:0}};o.viewer.isAuthor=((i=t.author)==null?void 0:i.id)===s.id,o.viewer.isAssignee=((u=t.assignees)==null?void 0:u.some(b=>b.id===s.id))??!1,o.viewer.isReviewer=((l=t.reviews)==null?void 0:l.some(b=>b.reviewer.id===s.id))??!1,o.viewer.canMerge=((p=t.permissions)==null?void 0:p.canMerge)??!0,o.hasConflicts=t.mergeableState==="CONFLICTS",o.failingCI=((c=(d=t.headCommit)==null?void 0:d.buildStatuses)==null?void 0:c.some(b=>b.state==="ERROR"||b.state==="FAILED"))??!1,o.commentReviewCount=((g=t.reviews)==null?void 0:g.filter(b=>b.state==="COMMENTED").length)??0,o.approvalReviewCount=((m=t.reviews)==null?void 0:m.filter(b=>b.state==="APPROVED").length)??0,o.changeRequestReviewCount=((R=t.reviews)==null?void 0:R.filter(b=>b.state==="CHANGES_REQUESTED").length)??0;let a=(P=e==null?void 0:e.enrichedItemsByUniqueId)==null?void 0:P[t.uuid];return a!=null&&(o.viewer.enrichedItems=a,a.some(b=>b.type==="pin")&&(o.viewer.pinned=!0,o.priority-=800),a.some(b=>b.type==="snooze")&&(o.viewer.snoozed=!0)),(o.viewer.isAuthor||o.viewer.isAssignee&&!o.viewer.isReviewer)&&o.viewer.canMerge&&!o.failingCI&&t.mergeableState==="MERGEABLE"&&(!t.reviewDecision||t.reviewDecision==="APPROVED")&&(o.viewer.shouldMerge=!0,o.suggestedActionCategory=jt),o.viewer.isAuthor&&t.isDraft&&(o.suggestedActionCategory=Xt),o.viewer.isAuthor&&t.reviewDecision==="REVIEW_REQUESTED"&&(o.suggestedActionCategory=Vt,o.viewer.waitingOnReviews=!0),o.viewer.isAuthor&&t.reviewDecision==="COMMENTED"&&(o.suggestedActionCategory=Kt),o.viewer.isAuthor&&o.failingCI&&(o.suggestedActionCategory=zt),o.viewer.isAuthor&&o.hasConflicts&&(o.suggestedActionCategory=Ht),o.viewer.isAuthor&&t.reviewDecision==="CHANGES_REQUESTED"&&(o.suggestedActionCategory=Jt),o.viewer.isAuthor&&!((h=t.reviews)!=null&&h.length)&&(o.suggestedActionCategory=Mt,o.viewer.shouldAssignReviewer=!0),(y=t.reviews)!=null&&y.some(b=>b.reviewer.id===s.id&&b.state==="REVIEW_REQUESTED")&&(o.suggestedActionCategory=Wt,o.viewer.shouldReview=!0),o}),gr=(r,s,e)=>{let t={pinned:C(lt,"Pinned","thumbtack",-1),readyToMerge:C(pt,"Ready to Merge","code-merge",0),unassignedReviewers:C(dt,"Unassigned Reviewers","user-plus",1),failingCI:C(ct,"Failing CI","circle-x",2),conflicts:C(gt,"Resolve Conflicts","triangle-exclamation",3),needsMyReview:C(mt,"Needs My Review","eye",4),changesRequested:C(ht,"Suggested Changes","file-plus",5),reviewerCommented:C(ft,"Reviewer Commented","comment",6),waitingForReview:C(Rt,"Waiting for Review","circle-pause",7),draft:C(It,"Draft","compass-drafting",8),other:C(bt,"Other","ellipsis",9),snoozed:C(yt,"Snoozed","snooze",10)},o=Zt(r,s,e).reduce((a,i)=>(a[i.uuid]=i,a),{});return r.forEach(a=>{let i=o[a.uuid],u=!0;if(i.viewer.snoozed){t[yt].pullRequests.push(a);return}i.viewer.pinned&&t[lt].pullRequests.push(a),(i.viewer.isAuthor||i.viewer.isAssignee&&!i.viewer.isReviewer)&&i.viewer.canMerge&&i.mergeableState==="MERGEABLE"&&(!a.reviewDecision||a.reviewDecision==="APPROVED")&&(t[pt].pullRequests.push(a),u=!1),i.viewer.shouldAssignReviewer&&(t[dt].pullRequests.push(a),u=!1),i.viewer.isAuthor&&i.failingCI&&(t[ct].pullRequests.push(a),u=!1),i.viewer.isAuthor&&i.hasConflicts&&(t[gt].pullRequests.push(a),u=!1),i.viewer.shouldReview&&(t[mt].pullRequests.push(a),u=!1),i.viewer.isAuthor&&i.reviewDecision==="CHANGES_REQUESTED"&&(t[ht].pullRequests.push(a),u=!1),i.viewer.isAuthor&&i.reviewDecision==="COMMENTED"&&(t[ft].pullRequests.push(a),u=!1),i.viewer.isAuthor&&i.reviewDecision==="REVIEW_REQUESTED"&&(t[Rt].pullRequests.push(a),u=!1),i.isDraft&&(t[It].pullRequests.push(a),u=!1),u&&t[bt].pullRequests.push(a)}),Object.values(t).forEach(a=>{a.pullRequests.sort((i,u)=>o[i.uuid].priority-o[u.uuid].priority)}),t};var Le={};O(Le,{getIssueUniqueId:()=>mr,getPullRequestRank:()=>fr,getPullRequestUniqueId:()=>hr});var mr=(r,s="")=>{let e=[];return e.push(s),e.push(r),JSON.stringify(e)},hr=(r,s="")=>{let e=[];return e.push(s),e.push(r),JSON.stringify(e)},fr=(r,s,e)=>{var a,i,u;let t=0,n,o;return(a=r.reviews)==null||a.forEach(l=>{l.reviewer.id===s&&(n=l.state),l.state==="CHANGES_REQUESTED"?o="CHANGES_REQUESTED":l.state==="APPROVED"&&o!=="CHANGES_REQUESTED"&&(o="APPROVED")}),o||(o="REVIEW_REQUESTED"),((i=r.author)==null?void 0:i.id)===s?t+=1e3:(u=r.assignees)!=null&&u.find(l=>l.id===s)?t+=900:n==="REVIEW_REQUESTED"?t+=800:e&&(t+=700),o==="APPROVED"?r.mergeableState==="MERGEABLE"?t+=100:r.mergeableState==="CONFLICTS"?t+=90:t+=80:o=="CHANGES_REQUESTED"&&(t+=70),t};var $e={};O($e,{getIssueUniqueId:()=>Rr,getPullRequestUniqueId:()=>Ir});var Rr=(r,s="")=>{let e=[];return e.push(s),e.push(r),JSON.stringify(e)},Ir=(r,s="")=>{let e=[];return e.push(s),e.push(r),JSON.stringify(e)};var Ae={};O(Ae,{getIssueUniqueId:()=>br,getJiraServerIssueUniqueId:()=>yr});var br=(r,s,e)=>{let t=[];return t.push(""),t.push(r),t.push(s),t.push(e),JSON.stringify(t)},yr=(r,s,e)=>{let t=[];return t.push(e),t.push(""),t.push(r),t.push(s),JSON.stringify(t)};var Ge={};O(Ge,{getIssueUniqueId:()=>wr});var wr=(r,s,e,t="")=>{let n=[];return n.push(t),n.push(r),n.push(s),n.push(e),JSON.stringify(n)};var es=(a=>(a.Conflicts="conflicts",a.Failure="failure",a.NotSet="notSet",a.Queued="queued",a.RejectedByPolicy="rejectedByPolicy",a.Succeeded="succeeded",a))(es||{});var ts=(e=>(e.Completed="COMPLETED",e.NotPlanned="NOT_PLANNED",e))(ts||{});var Pr=r=>{let s={request:r==null?void 0:r.request};return{azureDevOps:new K({...s,...r==null?void 0:r.azureDevOps}),bitbucket:new V({...s,...r==null?void 0:r.bitbucket}),bitbucketServer:new X({...s,...r==null?void 0:r.bitbucketServer}),github:new Y({...s,...r==null?void 0:r.github}),gitlab:new Z({...s,...r==null?void 0:r.gitlab}),jira:new te({...s,...r==null?void 0:r.jira}),jiraServer:new se({...s,...r==null?void 0:r.jiraServer}),trello:new re({...s,...r==null?void 0:r.trello})}},qr=Pr;var Sr={azureDevOps:Ee,bitbucket:Ce,bitbucketServer:De,github:Le,gitlab:$e,gitProvider:Ue,jira:Ae,trello:Ge};
|
|
1085
|
+
`,variables:{fullPath:`${r}/${n}`,after:o}},t);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(yt))??[]}}};var hs="https://api.atlassian.com/ex/jira",be=10,wt=["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components","project"],Pt=(s,e,t)=>{var o,i,a,u;let r=s.fields.assignee,n=!t;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:we(s.fields.creator,e,n),updatedDate:new Date(s.fields.updated),assignees:r?[we(r,e,n)]:[],description:null,repository:null,project:{name:s.fields.project.name,resourceId:t??null,namespace:null},state:ys(s.fields.status),statusTransitions:((o=s.transitions)==null?void 0:o.map(fs))??[],components:((i=s.fields.components)==null?void 0:i.map(Is))??[],type:s.fields.issuetype.name,upvoteCount:((a=s.fields.votes)==null?void 0:a.votes)||0,labels:((u=s.fields.labels)==null?void 0:u.map(l=>({color:null,description:null,id:null,name:l})))??[]}},fs=s=>{let e;switch(s.to.statusCategory.name){case"To Do":e="TO_DO";break;case"In Progress":e="IN_PROGRESS";break;default:e="DONE";break}return{name:s.name,id:s.id,to:{id:s.to.id,name:s.to.name,color:s.to.statusCategory.colorName,category:e}}},Is=s=>({description:s.description??null,id:s.id,name:s.name}),Rs=(s,e,t)=>t&&s.name?`${e}/secure/ViewProfile.jspa?name=${encodeURIComponent(s.name)}`:`${e}/jira/people/${s.accountId}`,we=(s,e,t)=>({id:(t?s.key:s.accountId)??"",name:s.displayName,email:s.emailAddress,avatarUrl:s.avatarUrls["48x48"],username:s.displayName,url:Rs(s,e,t)}),ys=s=>{let e;switch(s.statusCategory.name){case"To Do":e="TO_DO";break;case"In Progress":e="IN_PROGRESS";break;default:e="DONE";break}return{id:s.id,name:s.name,color:s.statusCategory.colorName,category:e}},J=(s,e,t)=>t?`${e.baseUrl||hs}/${t}`:`${(e==null?void 0:e.baseUrl)||s.baseUrl}`,Pe=async(s,e,t,r={})=>{let{number:n,resourceId:o}=e||{},i=await s.request({url:`${J(s,r,o)}/rest/api/2/issue/${n}?fields=${wt.join(",")}&expand=transitions`,headers:f(r.token||s.token)});return{data:Pt(i.body,t,o)}},Ee=async(s,e,t,r={})=>{let{page:n,resourceId:o}=e||{},i=n??0,a=`statusCategory != Done AND (creator = currentUser() OR assignee = currentUser()
|
|
1086
|
+
OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUser())`,l=(await s.request({url:`${J(s,r,o)}/rest/api/2/search?jql=${a}&startAt=${i}&maxResults=${be}&fields=${wt.join(",")}&expand=transitions`,headers:f(r.token||s.token)})).body.issues.map(d=>Pt(d,t,o)),p=l.length==be;return{data:l,pageInfo:{hasNextPage:p,nextPage:p?i+l.length:null}}},qe=async(s,e,t,r={})=>{let{assigneeLogins:n,authorLogin:o,mentionLogin:i,page:a,project:u,resourceId:l}=e||{},p=a??0,d=[`project = "${u}"`,"statusCategory != Done"];o&&d.push(`creator in ("${o}")`),n&&n.length!==0&&d.push(`assignee in ("${n.join('", "')}")`),i&&d.push(`comment ~ "${i}"`);let g=(await s.request({url:`${J(s,r,l)}/rest/api/2/search?jql=${d.join(" AND ")}&startAt=${p}&maxResults=${be}&fields=${wt.join(",")}&expand=transitions`,headers:f(r.token||s.token)})).body.issues.map(I=>Pt(I,t,l)),m=g.length==be;return{data:g,pageInfo:{hasNextPage:m,nextPage:m?p+g.length:null}}},ve=async(s,e,t={})=>{let{issue:r,labels:n}=e;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:`${J(s,t,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}`,body:JSON.stringify(o),headers:{...f(t.token||s.token),"Content-Type":"application/json"}})},Se=async(s,e,t={})=>{let{issue:r,components:n}=e;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:`${J(s,t,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}`,body:JSON.stringify(o),headers:{...f(t.token||s.token),"Content-Type":"application/json"}})},Ce=async(s,e,t={})=>{let{issue:r,status:n}=e;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:`${J(s,t,r.project.resourceId??void 0)}/rest/api/2/issue/${r.id}/transitions`,body:JSON.stringify(o),headers:{...f(t.token||s.token),"Content-Type":"application/json"}})},De=async(s,e,t={})=>{let{resourceId:r,projectIdOrKey:n}=e,o=new URL(`${J(s,t,r)}/rest/api/2/project/${n}/components`);return{data:(await s.request({url:o.toString(),headers:f(t.token||s.token)})).body}};var se="https://api.atlassian.com/ex/jira",Et=100,ne=class extends A{constructor(){super(...arguments);this._resourceUrlCache={}}async getResourceUrl(t,r={}){var i;let n=r.token||this.config.token;if(!n)return null;let o=this._resourceUrlCache[n];return o?o[t.resourceId]??null:(await this.getJiraResourcesForCurrentUser(r),((i=this._resourceUrlCache[n])==null?void 0:i[t.resourceId])??null)}async getCurrentUserForResource(t,r={}){let n=await this.getResourceUrl({resourceId:t.resourceId},r),o=await this.config.request({url:`${r.baseUrl||se}/${t.resourceId}/rest/api/2/myself`,headers:f(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(t={}){let r=await this.config.request({url:`${t.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:f(t.token||this.config.token)}),n=t.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(t,r={}){let n=new URL(`${r.baseUrl||se}/${t.resourceId}/rest/api/2/project/search`);n.searchParams.set("maxResults",Et.toString()),t.cursor&&n.searchParams.set("startAt",t.cursor);let o=await this.config.request({url:n.toString(),headers:f(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:t.resourceId}))}}async getJiraProjectsForResources(t,r={}){let n=[];return await Promise.all(t.resourceIds.map(async o=>{let i=await this.getJiraProjectsForResource({resourceId:o},r);n.push(...i.data)})),{data:n}}async getAccountsForJiraProject(t,r={}){let{resourceId:n,projectKey:o,cursor:i}=t,a=await this.getResourceUrl({resourceId:n},r),u=new URL(`${r.baseUrl||se}/${n}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",Et.toString()),i&&u.searchParams.set("startAt",i),u.searchParams.set("project",o);let l=await this.config.request({url:u.toString(),headers:f(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=>we(p,a,!1))}}async getComponentsForJiraProject(t,r={}){return await De(this.config,t,r)}async getIssue(t,r={}){let n=await this.getResourceUrl({resourceId:t.resourceId},r);return await Pe(this.config,t,n,r)}async getIssuesForProject(t,r={}){let n=await this.getResourceUrl({resourceId:t.resourceId},r);return await qe(this.config,t,n,r)}async getIssuesForResourceForCurrentUser(t,r={}){let n=await this.getResourceUrl({resourceId:t.resourceId},r);return await Ee(this.config,t,n,r)}async setIssueStatus(t,r={}){await Ce(this.config,t,r)}async setIssueAssignee(t,r={}){let{issue:n,assignee:o}=t;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||se}/${n.project.resourceId}/rest/api/2/issue/${n.id}/assignee`,body:JSON.stringify(i),headers:{...f(r.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(t,r={}){await Se(this.config,t,r)}async setIssueLabels(t,r={}){await ve(this.config,t,r)}async getLabelsForResource(t,r={}){let{resourceId:n,cursor:o}=t,i=new URL(`${r.baseUrl||se}/${n}/rest/api/2/label`);i.searchParams.set("maxResults",Et.toString()),o&&i.searchParams.set("startAt",o);let a=await this.config.request({url:i.toString(),headers:f(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 oe=class extends k{async getCurrentUser(e={}){let t=await this.config.request({url:`${(e==null?void 0:e.baseUrl)||this.config.baseUrl}/rest/api/2/myself`,headers:f((e==null?void 0:e.token)||this.config.token)});return{data:{name:t.body.displayName,email:t.body.emailAddress,avatarUrl:t.body.avatarUrls["48x48"],id:t.body.key,username:t.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:f((e==null?void 0:e.token)||this.config.token)})).body.map(r=>({id:r.id,name:r.name}))}}async getIssue(e,t={}){if(!t.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await Pe(this.config,e,t.baseUrl,t)}async getIssuesForProject(e,t={}){if(!t.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await qe(this.config,e,t.baseUrl,t)}async getIssuesForResourceForCurrentUser(e,t={}){if(!t.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await Ee(this.config,e,t.baseUrl,t)}async setIssueStatus(e,t={}){await Ce(this.config,e,t)}async setIssueLabels(e,t={}){await ve(this.config,e,t)}async setIssueComponents(e,t={}){await Se(this.config,e,t)}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:f(e.token||this.config.token)})).body.results.map(({displayName:r})=>({color:null,description:null,id:null,name:r}))}}async getComponentsForJiraProject(e,t={}){return await De(this.config,e,t)}};var M="https://api.trello.com",bs=1e3,ws=(s,e)=>{let t=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(t.toISOString()),author:null,updatedDate:new Date(s.dateLastActivity),assignees:s.idMembers.map(r=>({id:r,username:null,name:null,email:null,avatarUrl:null,url:null})),description:null,state:e[s.idList??""]?{id:s.idList,name:e[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}))}},ie=class extends A{async getCurrentUser(e,t={}){let r=await this.config.request({url:`${t.baseUrl||M}/1/members/me?key=${e.appKey}&token=${t.token||this.config.token}`,headers:f(t.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(e,t={}){return{data:(await this.config.request({url:`${t.baseUrl||M}/1/members/me/boards?fields=name&key=${e.appKey}&token=${t.token||this.config.token}&filter=open`,headers:f(t.token||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getListsForTrelloBoard(e,t={}){let{appKey:r,boardId:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||M}/1/boards/${n}/lists?key=${r}&token=${t.token||this.config.token}`,headers:f(t.token||this.config.token)})).body}}async getAccountsForTrelloBoard(e,t={}){let{appKey:r,boardId:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||M}/1/boards/${n}/members?key=${r}&token=${t.token||this.config.token}`,headers:f(t.token||this.config.token)})).body.map(i=>({id:i.id,name:i.fullName,username:i.username,email:null,avatarUrl:null,url:null}))}}async getIssuesForBoard(e,t={}){let r=["-is:archived","sort:edited"],{appKey:n,boardId:o,filterText:i,assigneeLogins:a,trelloBoardListsById:u}=e||{};a&&r.push("@me");let l=`${i?`${i}`:""}${r.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${t.baseUrl||M}/1/search?key=${n}&query=${l}&cards_limit=${bs}&token=${t.token||this.config.token}`,headers:f(t.token||this.config.token)})).body.cards.map(d=>ws(d,u||{}))}}async updateIssue(e,t,r,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||M}/1/cards/${t.id}?key=${e}&token=${n.token||this.config.token}&${r}`,headers:f(n.token||this.config.token)})}async setIssueStatus(e,t={}){let{appKey:r,issue:n,status:o}=e;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,t)).body.id)throw new Error("Could not set issue status")}async setIssueAssignees(e,t={}){let{appKey:r,issue:n,assignees:o}=e,i=o.map(l=>l.id),a=`idMembers=${encodeURIComponent(i.join(","))}`;if(!(await this.updateIssue(r,n,a,t)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(e,t={}){let{appKey:r,issue:n,labels:o}=e,i=o.map(u=>u.id).join(",");if(!(await this.config.request({method:"PUT",url:`${t.baseUrl||M}/1/cards/${n.id}?key=${r}&token=${t.token||this.config.token}&idLabels=${encodeURIComponent(i)}`,headers:f(t.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(e,t={}){let{appKey:r,issue:n,archived:o}=e;if(!(await this.config.request({method:"PUT",url:`${t.baseUrl||M}/1/cards/${n.id}?key=${r}&token=${t.token||this.config.token}&closed=${o}`,headers:f(t.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async archiveIssue(e,t={}){await this.setIssueArchived({...e,archived:!0},t)}async unArchiveIssue(e,t={}){await this.setIssueArchived({...e,archived:!1},t)}async getLabelsForBoard(e,t={}){let{appKey:r,boardId:n}=e;return{data:(await this.config.request({url:`${t.baseUrl||M}/1/boards/${n}/labels?key=${r}&token=${t.token||this.config.token}`,headers:f(t.token||this.config.token)})).body.map(i=>({color:i.color,description:null,id:i.id,name:i.name}))}}};var Le={};T(Le,{default:()=>Ps});var Ps={};var Ue={};T(Ue,{default:()=>Es});var Es={};var $e={};T($e,{default:()=>qs});var qs={};var Me={};T(Me,{decode:()=>Ds,decodeV0:()=>Ls,encode:()=>Cs,validate:()=>Ss});var Ae=class{constructor(){}validate(e){if(!e.organizationName)throw new Error("organizationName is required");if(!e.projectId)throw new Error("projectId is required");if(!e.entityId)throw new Error("issueId is required")}encode(e){if(this.validate(e),!e.organizationName||!e.projectId||!e.entityId)throw new Error("Missing required fields for Azure DevOps issue uniqueId");let t=[];return t.push("0"),t.push("1"),t.push("1"),t.push(e.domain||""),t.push(e.organizationName),t.push(e.projectId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<7)throw new Error("Invalid Azure DevOps issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:e[4],projectId:e[5],repoId:null,entityId:e[6]}}};var Ge=class{constructor(){}validate(e){if(!e.organizationName)throw new Error("organizationName is required");if(!e.projectId)throw new Error("projectId is required");if(!e.repoId)throw new Error("repoId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.organizationName||!e.projectId||!e.repoId||!e.entityId)throw new Error("Missing required fields for Azure DevOps pull request uniqueId");let t=[];return t.push("0"),t.push("0"),t.push("1"),t.push(e.domain||""),t.push(e.organizationName),t.push(e.projectId),t.push(e.repoId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<8)throw new Error("Invalid Azure DevOps pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:e[4],projectId:e[5],repoId:e[6],entityId:e[7]}}};var Oe=class{constructor(){}validate(e){if(!e.repoId)throw new Error("repoId is required");if(!e.entityId)throw new Error("issueId is required")}encode(e){if(this.validate(e),!e.repoId||!e.entityId)throw new Error("Missing required fields for Bitbucket DevOps issue uniqueId");let t=[];return t.push(e.domain?"6":"5"),t.push("1"),t.push("1"),t.push(e.domain||""),t.push(e.repoId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<6)throw new Error("Invalid Bitbucket DevOps issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:e[4],entityId:e[5]}}};var Te=class{constructor(){}validate(e){if(!e.repoId)throw new Error("repoId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.repoId||!e.entityId)throw new Error("Missing required fields for Bitbucket DevOps pull request uniqueId");let t=[];return t.push(e.domain?"6":"5"),t.push("0"),t.push("1"),t.push(e.domain||""),t.push(e.repoId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<6)throw new Error("Invalid Bitbucket DevOps pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:e[4],entityId:e[5]}}};var ke=class{constructor(){}validate(e){if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Github issue uniqueId");let t=[];return t.push(e.domain?"2":"1"),t.push("1"),t.push("1"),t.push(e.domain||""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Github issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var xe=class{constructor(){}validate(e){if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Github pull request uniqueId");let t=[];return t.push("1"),t.push("0"),t.push("1"),t.push(e.domain||""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Github pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var _e=class{constructor(){}validate(e){if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Gitlab issue uniqueId");let t=[];return t.push(e.domain?"4":"3"),t.push("1"),t.push("1"),t.push(e.domain||""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Gitlab issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var Ne=class{constructor(){}validate(e){if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Gitlab pull request uniqueId");let t=[];return t.push("3"),t.push("0"),t.push("1"),t.push(e.domain||""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Gitlab pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var Qe=class{constructor(){}validate(e){if(!e.resourceId)throw new Error("resourceId is required");if(!e.projectId)throw new Error("projectId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.resourceId||!e.projectId||!e.entityId)throw new Error("Missing required fields for Jira issue uniqueId");let t=[];return t.push(e.domain?"8":"7"),t.push("1"),t.push("1"),t.push(e.domain||""),t.push(e.resourceId),t.push(e.projectId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<7)throw new Error("Invalid Jira issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:e[4],accountOrOrgId:null,organizationName:null,projectId:e[5],repoId:null,entityId:e[6]}}};var Be=class{constructor(){}validate(e){if(!e.accountOrOrgId)throw new Error("resourceId is required");if(!e.projectId)throw new Error("projectId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.accountOrOrgId||!e.projectId||!e.entityId)throw new Error("Missing required fields for Trello issue uniqueId");let t=[];return t.push("9"),t.push("1"),t.push("1"),t.push(e.domain||""),t.push(e.accountOrOrgId),t.push(e.projectId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<7)throw new Error("Invalid Trello issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:e[4],organizationName:null,projectId:e[5],repoId:null,entityId:e[6]}}};var je=(s,e)=>{if(!e)throw new Error("entityType is required");if(!s)throw new Error("provider is required");switch(s){case"0":return e==="0"?new Ge:new Ae;case"5":case"6":return e==="0"?new Te:new Oe;case"1":case"2":return e==="0"?new xe:new ke;case"3":case"4":return e==="0"?new Ne:new _e;case"7":case"8":if(e==="0")throw new Error("EntityType PullRequest is not valid for Jira");return new Qe;case"9":if(e==="0")throw new Error("EntityType PullRequest is not valid for Jira");return new Be;default:throw new Error("unknown provider")}},vs=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")},Ss=s=>{if(s.version==="0"){vs(s);return}je(s.provider,s.entityType).validate(s)},Cs=s=>je(s.provider,s.entityType).encode(s),Ds=s=>{let e=JSON.parse(s);if(!e||!e.length)throw new Error("invalid issue unique id");return je(e[0],e[1]).decode(e)},Ls=(s,e,t)=>{if(!t)throw new Error("entityID is required");try{let r=JSON.parse(t);if(!r||!r.length)throw new Error("Invalid pull request uniqueId");let n=[s,e,"0",...r];return je(s,e).decode(n)}catch{return{provider:s,entityType:e,version:"0",domain:"",resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:t}}};var Fe={};T(Fe,{CHANGES_REQUESTED_ACTION_CATEGORY:()=>lr,CHANGES_REQUESTED_BUCKET_ID:()=>Ut,CONFLICTS_ACTION_CATEGORY:()=>ar,CONFLICTS_BUCKET_ID:()=>Dt,DRAFT_ACTION_CATEGORY:()=>cr,DRAFT_BUCKET_ID:()=>Gt,FAILING_CI_ACTION_CATEGORY:()=>ir,FAILING_CI_BUCKET_ID:()=>Ct,NEEDS_MY_REVIEW_ACTION_CATEGORY:()=>ur,NEEDS_MY_REVIEW_BUCKET_ID:()=>Lt,OTHER_ACTION_CATEGORY:()=>gr,OTHER_BUCKET_ID:()=>Ot,PINNED_BUCKET_ID:()=>qt,READY_TO_MERGE_ACTION_CATEGORY:()=>nr,READY_TO_MERGE_BUCKET_ID:()=>vt,REVIEWER_COMMENTED_ACTION_CATEGORY:()=>pr,REVIEWER_COMMENTED_BUCKET_ID:()=>$t,SNOOZED_BUCKET_ID:()=>Tt,UNASSIGNED_REVIEWERS_ACTION_CATEGORY:()=>or,UNASSIGNED_REVIEWERS_BUCKET_ID:()=>St,WAITING_FOR_REVIEW_ACTION_CATEGORY:()=>dr,WAITING_FOR_REVIEW_BUCKET_ID:()=>At,getActionablePullRequests:()=>mr,groupPullRequestsIntoBuckets:()=>Us});var U=(s,e,t,r)=>({id:s,faIconName:t,name:e,priority:r,pullRequests:[]}),qt="pinned",vt="readyToMerge",St="unassignedReviewers",Ct="failingCI",Dt="conflicts",Lt="needsMyReview",Ut="changesRequested",$t="reviewerCommented",At="waitingForReview",Gt="draft",Ot="other",Tt="snoozed",nr="readyToMerge",or="unassignedReviewers",ir="failingCI",ar="conflicts",ur="needsMyReview",lr="changesRequested",pr="reviewerCommented",dr="waitingForReview",cr="draft",gr="other",mr=(s,e,t)=>s.map(r=>{var a,u,l,p,d,c,g,m,I,P,h,b;let o={...r,...{suggestedActionCategory:gr,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,commentReviewCount:0,approvalReviewCount:0}};o.viewer.isAuthor=((a=r.author)==null?void 0:a.id)===e.id,o.viewer.isAssignee=((u=r.assignees)==null?void 0:u.some(y=>y.id===e.id))??!1,o.viewer.isReviewer=((l=r.reviews)==null?void 0:l.some(y=>y.reviewer.id===e.id))??!1,o.viewer.canMerge=((p=r.permissions)==null?void 0:p.canMerge)??!0,o.hasConflicts=r.mergeableState==="CONFLICTS",o.failingCI=((c=(d=r.headCommit)==null?void 0:d.buildStatuses)==null?void 0:c.some(y=>y.state==="ERROR"||y.state==="FAILED"))??!1,o.commentReviewCount=((g=r.reviews)==null?void 0:g.filter(y=>y.state==="COMMENTED").length)??0,o.approvalReviewCount=((m=r.reviews)==null?void 0:m.filter(y=>y.state==="APPROVED").length)??0,o.changeRequestReviewCount=((I=r.reviews)==null?void 0:I.filter(y=>y.state==="CHANGES_REQUESTED").length)??0;let i=(P=t==null?void 0:t.enrichedItemsByUniqueId)==null?void 0:P[r.uuid];return i!=null&&(o.viewer.enrichedItems=i,i.some(y=>y.type==="pin")&&(o.viewer.pinned=!0,o.priority-=800),i.some(y=>y.type==="snooze")&&(o.viewer.snoozed=!0)),(o.viewer.isAuthor||o.viewer.isAssignee&&!o.viewer.isReviewer)&&o.viewer.canMerge&&!o.failingCI&&r.mergeableState==="MERGEABLE"&&(!r.reviewDecision||r.reviewDecision==="APPROVED")&&(o.viewer.shouldMerge=!0,o.suggestedActionCategory=nr),o.viewer.isAuthor&&r.isDraft&&(o.suggestedActionCategory=cr),o.viewer.isAuthor&&r.reviewDecision==="REVIEW_REQUESTED"&&(o.suggestedActionCategory=dr,o.viewer.waitingOnReviews=!0),o.viewer.isAuthor&&r.reviewDecision==="COMMENTED"&&(o.suggestedActionCategory=pr),o.viewer.isAuthor&&o.failingCI&&(o.suggestedActionCategory=ir),o.viewer.isAuthor&&o.hasConflicts&&(o.suggestedActionCategory=ar),o.viewer.isAuthor&&r.reviewDecision==="CHANGES_REQUESTED"&&(o.suggestedActionCategory=lr),o.viewer.isAuthor&&!((h=r.reviews)!=null&&h.length)&&(o.suggestedActionCategory=or,o.viewer.shouldAssignReviewer=!0),(b=r.reviews)!=null&&b.some(y=>y.reviewer.id===e.id&&y.state==="REVIEW_REQUESTED")&&(o.suggestedActionCategory=ur,o.viewer.shouldReview=!0),o}),Us=(s,e,t)=>{let r={pinned:U(qt,"Pinned","thumbtack",-1),readyToMerge:U(vt,"Ready to Merge","code-merge",0),unassignedReviewers:U(St,"Unassigned Reviewers","user-plus",1),failingCI:U(Ct,"Failing CI","circle-x",2),conflicts:U(Dt,"Resolve Conflicts","triangle-exclamation",3),needsMyReview:U(Lt,"Needs My Review","eye",4),changesRequested:U(Ut,"Suggested Changes","file-plus",5),reviewerCommented:U($t,"Reviewer Commented","comment",6),waitingForReview:U(At,"Waiting for Review","circle-pause",7),draft:U(Gt,"Draft","compass-drafting",8),other:U(Ot,"Other","ellipsis",9),snoozed:U(Tt,"Snoozed","snooze",10)},o=mr(s,e,t).reduce((i,a)=>(i[a.uuid]=a,i),{});return s.forEach(i=>{let a=o[i.uuid],u=!0;if(a.viewer.snoozed){r[Tt].pullRequests.push(i);return}a.viewer.pinned&&r[qt].pullRequests.push(i),(a.viewer.isAuthor||a.viewer.isAssignee&&!a.viewer.isReviewer)&&a.viewer.canMerge&&a.mergeableState==="MERGEABLE"&&(!i.reviewDecision||i.reviewDecision==="APPROVED")&&(r[vt].pullRequests.push(i),u=!1),a.viewer.shouldAssignReviewer&&(r[St].pullRequests.push(i),u=!1),a.viewer.isAuthor&&a.failingCI&&(r[Ct].pullRequests.push(i),u=!1),a.viewer.isAuthor&&a.hasConflicts&&(r[Dt].pullRequests.push(i),u=!1),a.viewer.shouldReview&&(r[Lt].pullRequests.push(i),u=!1),a.viewer.isAuthor&&a.reviewDecision==="CHANGES_REQUESTED"&&(r[Ut].pullRequests.push(i),u=!1),a.viewer.isAuthor&&a.reviewDecision==="COMMENTED"&&(r[$t].pullRequests.push(i),u=!1),a.viewer.isAuthor&&a.reviewDecision==="REVIEW_REQUESTED"&&(r[At].pullRequests.push(i),u=!1),a.isDraft&&(r[Gt].pullRequests.push(i),u=!1),u&&r[Ot].pullRequests.push(i)}),Object.values(r).forEach(i=>{i.pullRequests.sort((a,u)=>o[a.uuid].priority-o[u.uuid].priority)}),r};var ze={};T(ze,{getPullRequestRank:()=>$s});var $s=(s,e,t)=>{var i,a,u;let r=0,n,o;return(i=s.reviews)==null||i.forEach(l=>{l.reviewer.id===e&&(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)===e?r+=1e3:(u=s.assignees)!=null&&u.find(l=>l.id===e)?r+=900:n==="REVIEW_REQUESTED"?r+=800:t&&(r+=700),o==="APPROVED"?s.mergeableState==="MERGEABLE"?r+=100:s.mergeableState==="CONFLICTS"?r+=90:r+=80:o=="CHANGES_REQUESTED"&&(r+=70),r};var He={};T(He,{default:()=>As});var As={};var We={};T(We,{default:()=>Gs});var Gs={};var Je={};T(Je,{default:()=>Os});var Os={};var hr=(i=>(i.Conflicts="conflicts",i.Failure="failure",i.NotSet="notSet",i.Queued="queued",i.RejectedByPolicy="rejectedByPolicy",i.Succeeded="succeeded",i))(hr||{});var fr=(t=>(t.Completed="COMPLETED",t.NotPlanned="NOT_PLANNED",t))(fr||{});var Ts=s=>{let e={request:s==null?void 0:s.request};return{azureDevOps:new Y({...e,...s==null?void 0:s.azureDevOps}),bitbucket:new Z({...e,...s==null?void 0:s.bitbucket}),bitbucketServer:new ee({...e,...s==null?void 0:s.bitbucketServer}),github:new te({...e,...s==null?void 0:s.github}),gitlab:new re({...e,...s==null?void 0:s.gitlab}),jira:new ne({...e,...s==null?void 0:s.jira}),jiraServer:new oe({...e,...s==null?void 0:s.jiraServer}),trello:new ie({...e,...s==null?void 0:s.trello})}},ks=Ts;var xs={azureDevOps:Le,bitbucket:Ue,bitbucketServer:$e,github:ze,gitlab:He,gitProvider:Fe,jira:We,trello:Je,entityIdentifier:Me};
|