@gitkraken/provider-apis 0.17.3 → 0.17.4
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 +12 -0
- package/dist/index.js +109 -88
- package/dist/providers/gitProvider.d.ts +5 -0
- package/dist/providers/github/github.d.ts +19 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.17.4
|
|
4
|
+
|
|
5
|
+
- added `getPullRequestForRepo` (GitHub)
|
|
6
|
+
- added `getPullRequestByGraphQLId` (GitHub)
|
|
7
|
+
- added `getFileContents` (GitHub)
|
|
8
|
+
- fix normalization of `repository` in `GitPullRequest` (Bitbucket)
|
|
9
|
+
|
|
10
|
+
## 0.17.3
|
|
11
|
+
|
|
12
|
+
- added `login` field to `repository` object in `GitPullRequest` type (Azure DevOps, BitBucket)
|
|
13
|
+
- made `login` field required for `repository` object in `GitPullRequest` type (since all providers support it now)
|
|
14
|
+
|
|
3
15
|
## 0.17.2
|
|
4
16
|
|
|
5
17
|
- add a `forceIsFetch` config option for cases where the native `fetch` function has been overridden but still uses `fetch` under the hood
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var St=Object.create;var re=Object.defineProperty;var Dt=Object.getOwnPropertyDescriptor;var Et=Object.getOwnPropertyNames;var Ct=Object.getPrototypeOf,qt=Object.prototype.hasOwnProperty;var T=(t,s)=>{for(var e in s)re(t,e,{get:s[e],enumerable:!0})},et=(t,s,e,r)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of Et(s))!qt.call(t,n)&&n!==e&&re(t,n,{get:()=>s[n],enumerable:!(r=Dt(s,n))||r.enumerable});return t};var vt=(t,s,e)=>(e=t!=null?St(Ct(t)):{},et(s||!t||!t.__esModule?re(e,"default",{value:t,enumerable:!0}):e,t)),Ut=t=>et(re({},"__esModule",{value:!0}),t);var tr={};T(tr,{AzureDevOps:()=>W,AzureDevopsUtils:()=>be,Bitbucket:()=>H,BitbucketServer:()=>J,BitbucketServerUtils:()=>Pe,BitbucketUtils:()=>ye,GitHub:()=>K,GitHubUtils:()=>Se,GitLab:()=>X,GitLabUtils:()=>De,GitProviderUtils:()=>we,Jira:()=>Z,JiraServer:()=>ee,JiraUtils:()=>Ee,Trello:()=>te,TrelloUtils:()=>Ce,Utils:()=>er,default:()=>Zs});module.exports=Ut(tr);var E=100;var tt=vt(require("node-fetch")),st=globalThis.fetch||tt.default;var $t=async t=>{let s=t.headers.get("content-type")||"",e=null;if(s.startsWith("application/json")){let n=await t.text();e=n.trim().length>0?JSON.parse(n):null}else if(s.startsWith("text/")||s==="")e=await t.text();else throw new Error(`Unsupported content-type: ${s}`);let r={body:e,headers:Object.fromEntries(t.headers.entries()),status:t.status,statusText:t.statusText};if(!t.ok){let n=new Error(t.statusText);throw Object.assign(n,{response:r}),n}return r},qe=t=>async({url:s,...e})=>{let r=await t(s,e);return $t(r)};var ve=(t,s=!1)=>t.name==="fetch"||s;var v=class{constructor(s){let e=(s==null?void 0:s.request)||st;this.config={...s,request:ve(e,s==null?void 0:s.forceIsFetch)?qe(e):e}}updateConfig(s){this.config={...this.config,...s,request:s.request&&ve(s.request,(s==null?void 0:s.forceIsFetch)??this.config.forceIsFetch)?qe(s.request):this.config.request}}},L=class extends v{};var R=(t,s)=>{let e={};return t&&(e.Authorization=`${s?"Basic":"Bearer"} ${t}`),e},rt=t=>t?t.reduce((s,e)=>(s[e]=!0,s),{}):void 0,_=(t,s,e)=>!t||s.some(r=>t[r])?e:"";var w=(t,s={})=>R(s.token||t.token,s.isPAT||t.isPAT),nt=t=>t.url.replace("/_apis/git/repositories/","/_git/").replace(`/${t.repository.project.id}/`,`/${encodeURIComponent(t.repository.project.name)}/`).replace(`/${t.repository.id}/`,`/${encodeURIComponent(t.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var at={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},N=t=>!t||t.length===0?null:t.reduce((s,e)=>at[e.state]>at[s]?e.state:s,"APPROVED");var ot="https://app.vssps.visualstudio.com/_apis",S="https://dev.azure.com",Lt={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Gt={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},Ue=t=>({id:t.id,name:t.displayName,username:t.uniqueName||t.displayName,email:null,avatarUrl:t.imageUrl,url:null}),ae=t=>t.startsWith("refs/heads/")?t.replace("refs/heads/",""):t,ne=(t,s)=>{var r;let e=s.reviewers.filter(n=>n.vote!==0).map(n=>({reviewer:Ue(n),state:Gt[n.vote]||"REVIEW_REQUESTED"}));return{id:s.pullRequestId.toString(),title:s.title,number:s.codeReviewId,state:Lt[s.status],isDraft:s.isDraft,commentCount:null,upvoteCount:null,author:Ue(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:t},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:ae(s.targetRefName),oid:s.lastMergeTargetCommit.commitId},headRef:{name:ae(s.sourceRefName),oid:s.lastMergeSourceCommit.commitId},url:nt(s),assignees:s.reviewers.map(Ue),reviews:e,reviewDecision:N(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((r=s.labels)==null?void 0:r.map(n=>({color:null,description:null,id:n.id,name:n.name})))??[],permissions:null}},it=(t,s)=>({id:s.id,name:s.name,namespace:t,project:s.project.name,webUrl:s.webUrl,httpsUrl:s.remoteUrl,sshUrl:s.sshUrl,defaultBranch:s.defaultBranch?{name:ae(s.defaultBranch)}:null,permission:null}),At=(t,s)=>{var i,u;let e=t.fields,r=e["System.AssignedTo"],n=e["System.State"],o=e["System.WorkItemType"],a;return n&&o&&(a=(i=s[o])==null?void 0:i[n]),{id:t.id.toString(),number:t.id.toString(),title:e["System.Title"],commentCount:e["System.CommentCount"],author:{avatarUrl:e["System.CreatedBy"]._links.avatar.href,email:null,id:e["System.CreatedBy"].id,name:e["System.CreatedBy"].uniqueName,username:e["System.CreatedBy"].displayName,url:null},closedDate:e["Microsoft.VSTS.Common.ClosedDate"]?new Date(e["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(e["System.CreatedDate"]),updatedDate:new Date(e["System.ChangedDate"]),url:t._links.html.href,assignees:r?[{avatarUrl:r._links.avatar.href,email:null,id:r.id,name:r.uniqueName,username:r.displayName,url:null}]:[],description:null,state:{name:(a==null?void 0:a.title)||n,color:null},type:e["System.WorkItemType"],repository:null,upvoteCount:0,labels:((u=t.fields["System.Tags"])==null?void 0:u.split(";").map(l=>({color:null,description:null,id:null,name:l.trim()})))??[]}},W=class extends v{async getCurrentUser(s={},e={}){if(e.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let r=await this.config.request({url:`${ot}/profile/profiles/me`,headers:w(this.config,e)});return{data:{id:r.body.id,name:r.body.displayName,username:r.body.displayName,email:r.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(s,e={}){let n=(await this.config.request({url:`${S}/${encodeURIComponent(s.namespace)}/_apis/ConnectionData`,headers:w(this.config,e)})).body.authorizedUser;if(n.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:n.id,name:n.providerDisplayName,username:n.providerDisplayName,email:n.properties.Account.$value,avatarUrl:null}}}async getUserForCommit(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:w(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:`${ot}/accounts?memberId=${s.userId}&api-version=6.0`,headers:w(this.config,e)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(s,e={}){let r=new URL(`${S}/${encodeURIComponent(s.namespace)}/_apis/projects`);r.searchParams.set("$top",E.toString()),s.cursor&&r.searchParams.set("$skip",s.cursor);let n=await this.config.request({url:r.toString(),headers:w(this.config,e)}),o=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:n.body.value.map(a=>({id:a.id,name:a.name,namespace:s.namespace}))}}async getAzureProjectScopeDescriptor(s,e={}){let{namespace:r,projectId:n}=s;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:w(this.config,e)})).body.value}}}async getAzureGraphAccountsForAzureProject(s,e={}){let{namespace:r,projectScopeDescriptor:n,cursor:o}=s,a=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_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:w(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:r}=s,n=await this.config.request({url:r.storageKeyURL,headers:w(this.config,e)});return{data:{avatarUrl:r.avatarUrl,email:r.email,id:n.body.value,name:r.name,username:r.username,url:null}}}async getAccountsFromAzureGraphAccounts(s,e={}){let r=[];for(let n of s.azureGraphAccounts){let o=await this.getAccountFromAzureGraphAccount({azureGraphAccount:n},e);r.push(o.data)}return{data:r}}async getRepo(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=await this.config.request({url:`${S}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories/${encodeURIComponent(s.name)}`,headers:w(this.config,e)});return{data:it(s.namespace,r.body)}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);r.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:r,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:w(this.config,e)})).body.value.map(n=>it(s.namespace,n))}}async getRefs(s,e,r={}){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",E.toString()),e.cursor&&n.searchParams.set("continuationToken",e.cursor);let o=await this.config.request({url:n.toString(),headers:w(this.config,r)}),a=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:o.body.value.map(i=>({name:ae(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={},r=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=${r}&%24skip=${(u-1)*r}`,headers:w(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=>ne(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:r}=s||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...s},e)).body.value.forEach(i=>{n.push(ne(o.namespace,i))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:n}}async getPullRequestsForProjectBase(s,e={},r=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",r.toString()),p.searchParams.set("$skip",((l-1)*r).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:w(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=>ne(s.namespace,a))}}async getPullRequestsForProjects(s,e={}){let{projects:r}=s||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForProjectBase({...o,...s},e)).body.value.forEach(i=>{n.push(ne(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:r,project:n,name:o},pullRequestId:a}=s,i=await this.config.request({url:`${e.baseUrl||S}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}?includeCommits=true?api-version=6.0`,headers:{...w(this.config,e)}});if(!i.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:i.body.mergeStatus}}async updatePullRequest(s,e,r,n){let{namespace:o,project:a,name:i}=s;return await this.config.request({method:"PATCH",url:`${n.baseUrl||S}/${encodeURIComponent(o)}/${encodeURIComponent(a||"")}/_apis/git/repositories/${i}/pullrequests/${e}?api-version=6.0`,body:r,headers:{...w(this.config,n),"Content-Type":"application/json"}})}async closePullRequest(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n}=s,o={status:"abandoned"};if(!(await this.updatePullRequest(r,n,JSON.stringify(o),e)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n,expectedSourceSha:o,mergeStrategy:a}=s,i;switch(a){case"MERGE_COMMIT":{i="noFastForward";break}case"REBASE":{i="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{i="rebaseMerge";break}case"SQUASH":{i="squash";break}}let u={completionOptions:{mergeStrategy:i},lastMergeSourceCommit:{commitId:o},status:"completed"};if(!(await this.updatePullRequest(r,n,JSON.stringify(u),e)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(s,e={}){let{repo:{namespace:r,project:n,name:o},pullRequestId:a,labelName:i}=s;if(!n)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let u={name:i};if(!(await this.config.request({method:"POST",url:`${e.baseUrl||S}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}/labels?api-version=6.0`,body:JSON.stringify(u),headers:{...w(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(s,e={}){let{repo:{namespace:r,project:n,name:o},pullRequestId:a,labelNameOrId:i}=s;if(!n)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(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}/labels/${encodeURIComponent(i)}?api-version=6.0`,headers:{...w(this.config,e)}})}async setPullRequestAsDraft(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n,isDraft:o}=s,a={isDraft:o};if(!(await this.updatePullRequest(r,n,JSON.stringify(a),e)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(s,e={}){if(!s.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:a,reviewerId:i,isRequired:u}=s,l={id:i,isRequired:u};if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||S}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}/reviewers/${i}?api-version=6.0`,body:JSON.stringify(l),headers:{...w(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(s,e={}){if(!s.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:a,reviewerId:i}=s;await this.config.request({method:"DELETE",url:`${e.baseUrl||S}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}/reviewers/${i}?api-version=6.0`,headers:{...w(this.config,e),Accept:"application/json"}})}async getIssuesForAzureProject(s,e={}){let{page:r,assigneeLogins:n,authorLogin:o,mentionLogin:a,statusByWorkItemIdByStatusId:i}=s||{},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("'","''")}'`),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:{...w(this.config,e),"Content-Type":"application/json"}}),g=c.body.workItems.slice((u-1)*l,l*u).map(f=>f.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:{...w(this.config,e),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:c.body.workItems.length>l*u,nextPage:u+1},data:m.body.value.map(f=>At(f,i||{}))}}async updateIssue(s,e,r,n,o={}){return await this.config.request({method:"PATCH",url:`${o.baseUrl||S}/${encodeURIComponent(s)}/${encodeURIComponent(e||"")}/_apis/wit/workitems/${r}?api-version=6.0`,body:JSON.stringify(n),headers:{...w(this.config,o),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(s,e={}){var l;if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n,issueId:o,status:a}=s,i=[{op:"add",path:"/fields/System.State",value:a}];if(!((l=(await this.updateIssue(r,n,o,i,e)).body.fields)!=null&&l["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(s,e={}){var l;if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n,issueId:o,assigneeNameOrEmail:a}=s,i=[{op:"add",path:"/fields/System.AssignedTo",value:a??""}];if(!((l=(await this.updateIssue(r,n,o,i,e)).body.fields)!=null&&l["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(s,e={}){var l;let{namespace:r,project:n,issueId:o,tagNames:a}=s,i=[{op:"replace",path:"/fields/System.Tags",value:a.join(";")}];if(!((l=(await this.updateIssue(r,n,o,i,e)).body.fields)!=null&&l["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:r,project:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||S}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...w(this.config,e)}})).body.value}}async getLabelsForProject(s,e={}){let{namespace:r,project:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||S}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...w(this.config,e)}})).body.value.map(a=>({color:null,description:null,id:a.id,name:a.name}))}}};var q=(t,s={})=>R(s.token||t.token,s.isPAT||t.isPAT);var U="https://api.bitbucket.org/2.0",Tt={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},lt=t=>({id:t.uuid,name:t.display_name||t.nickname,username:t.nickname||t.display_name,email:null,avatarUrl:t.links.avatar.href,url:t.links.html.href}),ut=t=>{var s,e;return{id:t.uuid,namespace:t.workspace.slug,name:t.slug,webUrl:t.links.html.href,httpsUrl:((s=t.links.clone.find(r=>r.name==="https"))==null?void 0:s.href)??null,sshUrl:((e=t.links.clone.find(r=>r.name==="ssh"))==null?void 0:e.href)??null,defaultBranch:{name:t.mainbranch.name},permission:null}},Le=t=>{let s=t.id;return{id:s.toString(),title:t.title,number:s,state:Tt[t.state],isDraft:!1,commentCount:t.comment_count,upvoteCount:null,author:lt(t.author),createdDate:new Date(t.created_on),updatedDate:new Date(t.updated_on),closedDate:null,mergedDate:null,repository:{id:t.source.repository.uuid,name:t.source.repository.name,owner:{login:t.source.repository.full_name.split("/")[0]},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:t.destination.branch.name,oid:t.destination.commit.hash},headRef:{name:t.source.branch.name,oid:t.source.commit.hash},url:t.links.html.href,assignees:null,reviews:null,reviewDecision:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",permissions:null}},H=class extends v{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 r=await this.config.request({url:`${U}/user`,headers:q(this.config,e)});return{data:lt(r.body)}}async getUserForCommit(s,e={}){var a;let n=(await this.config.request({url:`${U}/repositories/${s.repo.namespace}/${s.repo.name}/commit/${s.oid}`,headers:q(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 r=await this.config.request({url:`${U}/repositories/${s.namespace}/${s.name}`,headers:q(this.config,e)});return{data:ut(r.body)}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);r.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:r,errors:n}}async getReposForCurrentUser(s={},e={}){let r=new URL(`${U}/repositories`);r.searchParams.set("role","member"),r.searchParams.set("pagelen",E.toString()),s.cursor&&r.searchParams.set("after",s.cursor);let n=await this.config.request({url:r.toString(),headers:q(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(ut)}}async getBranches(s,e={}){var a;let r=new URL(`${U}/repositories/${s.repo.namespace}/${s.repo.name}/refs/branches`);r.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),r.searchParams.set("pagelen",E.toString());let n=await this.config.request({url:r.toString(),headers:q(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 r=new URL(`${U}/repositories/${s.repo.namespace}/${s.repo.name}/refs/tags`);r.searchParams.set("pagelen",E.toString()),s.cursor&&r.searchParams.set("page",s.cursor);let n=await this.config.request({url:r.toString(),headers:q(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 r=new URL(`${U}/pullrequests/${s.userId}`);r.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),r.searchParams.set("pagelen","50");let n=await this.config.request({url:r.toString(),headers:q(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(Le)}}async getPullRequestsForRepoBase(s,e={}){var n;let r=new URL(`${U}/repositories/${encodeURI(s.repo.namespace)}/${encodeURI(s.repo.name)}/pullrequests?state=OPEN`);return r.searchParams.set("page",((n=s.page)==null?void 0:n.toString())||"1"),r.searchParams.set("pagelen","50"),await this.config.request({url:r.toString(),headers:q(this.config,e)})}async getPullRequestsForRepo(s,e={}){let r=[],n=await this.getPullRequestsForRepoBase(s,e);n.body.values.forEach(a=>{if(s.authorLogin&&a.author.uuid!==s.authorLogin)return null;r.push(Le(a))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:r}}async getPullRequestsForRepos(s,e={}){let r=[];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;r.push(Le(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async closePullRequest(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:o}=s;if(!(await this.config.request({method:"POST",url:`${U}/repositories/${r}/${n}/pullrequests/${o}/decline`,headers:q(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:o,mergeStrategy:a}=s,i;switch(a){case"MERGE_COMMIT":{i="merge_commit";break}case"FAST_FORWARD":{i="fast_forward";break}case"SQUASH":{i="squash";break}}let u={merge_strategy:i,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${U}/repositories/${r}/${n}/pullrequests/${o}/merge`,body:JSON.stringify(u),headers:{...q(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:o,reviewerUsernames:a}=s,i={reviewers:a.map(l=>({username:l}))};if(!(await this.config.request({method:"PUT",url:`${U}/repositories/${r}/${n}/pullrequests/${o}`,body:JSON.stringify(i),headers:{...q(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var pt=t=>({name:t.displayName,email:t.emailAddress,avatarUrl:null,id:t.id.toString(),username:t.name,url:t.links.self[0].href}),Ge=t=>{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"},r=t.reviewers.map(m=>({reviewer:pt(m.user),state:e[m.status]})),n=((u=t.toRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:u.href)??null,o=((l=t.toRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:l.href)??null;o||(o=((p=t.toRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:p.href)??null);let a=((d=t.fromRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:d.href)??null,i=((c=t.fromRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:c.href)??null;return i||(i=((g=t.fromRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:g.href)??null),{id:t.id.toString(),number:t.id,title:t.title,url:t.links.self[0].href,state:s[t.state],isDraft:!1,createdDate:new Date(t.createdDate),updatedDate:new Date(t.updatedDate),closedDate:t.closedDate?new Date(t.closedDate):null,mergedDate:t.state=="MERGED"&&t.closedDate?new Date(t.closedDate):null,baseRef:{name:t.toRef.displayId,oid:t.toRef.latestCommit},headRef:{name:t.fromRef.displayId,oid:t.fromRef.latestCommit},commentCount:t.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:pt(t.author.user),assignees:null,reviews:r,reviewDecision:N(r),repository:{id:t.toRef.repository.id.toString(),name:t.toRef.repository.name,owner:{login:t.toRef.repository.project.name},remoteInfo:o&&n?{cloneUrlHTTPS:o,cloneUrlSSH:n}:null},headRepository:{id:t.fromRef.repository.id.toString(),name:t.fromRef.repository.name,owner:{login:t.fromRef.repository.project.name},remoteInfo:i&&a?{cloneUrlHTTPS:i,cloneUrlSSH:a}:null},headCommit:null,mergeableState:"UNKNOWN",permissions:null}},J=class extends L{getBaseUrl(s){let e=s.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(s){return R(s.token||this.config.token)}async getRepo(s,e={}){var n,o,a;let r=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${s.namespace}/repos/${s.name}`,headers:this.getRequestHeaders(e)});return{data:{id:r.body.id.toString(),namespace:r.body.project.key,name:r.body.slug,webUrl:((n=r.body.links.self[0])==null?void 0:n.href)??null,httpsUrl:((o=r.body.links.clone.find(i=>i.name==="https"))==null?void 0:o.href)??null,sshUrl:((a=r.body.links.clone.find(i=>i.name==="ssh"))==null?void 0:a.href)??null,defaultBranch:null,permission:null}}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);r.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:r,errors:n}}async getPullRequestsForRepoBase(s,e={}){var n;let r=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(s.repo.namespace)}/repos/${encodeURI(s.repo.name)}/pull-requests?state=OPEN`);return r.searchParams.set("start",((n=s.page)==null?void 0:n.toString())||"0"),r.searchParams.set("limit","50"),await this.config.request({url:r.toString(),headers:this.getRequestHeaders(e)})}async getPullRequestsForRepo(s,e={}){let r=[],n=await this.getPullRequestsForRepoBase(s,e);n.body.values.forEach(a=>{if(s.authorLogin&&a.author.user.name!==s.authorLogin)return null;r.push(Ge(a))});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(s,e={}){let r=[];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;r.push(Ge(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async getPullRequestsForCurrentUser(s,e={}){var a;let r=new URL(`${this.getBaseUrl(e)}/dashboard/pull-requests`);r.searchParams.set("state","OPEN"),r.searchParams.set("start",((a=s.page)==null?void 0:a.toString())||"0"),r.searchParams.set("limit","50");let n=await this.config.request({url:r.toString(),headers:this.getRequestHeaders(e)}),o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:n.body.values.map(Ge)}}async closePullRequest(s,e){let{repo:{namespace:r,name:n},pullRequestId:o,version:a}=s;if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${o}/decline`,body:JSON.stringify({version:a}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e){let{repo:{namespace:r,name:n},pullRequestId:o,mergeStrategyId:a,version:i}=s;if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${o}/merge`,body:JSON.stringify({strategyId:a,version:i}),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{repo:{namespace:r,name:n},pullRequestId:o,reviewerUsernames:a,version:i}=s,u={reviewers:a.map(p=>({user:{name:p}})),version:i};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${o}`,body:JSON.stringify(u),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var ue="https://api.github.com",Ot=`${ue}/graphql`,le=`
|
|
1
|
+
"use strict";var St=Object.create;var re=Object.defineProperty;var Et=Object.getOwnPropertyDescriptor;var Ct=Object.getOwnPropertyNames;var vt=Object.getPrototypeOf,Ut=Object.prototype.hasOwnProperty;var T=(t,s)=>{for(var e in s)re(t,e,{get:s[e],enumerable:!0})},nt=(t,s,e,r)=>{if(s&&typeof s=="object"||typeof s=="function")for(let n of Ct(s))!Ut.call(t,n)&&n!==e&&re(t,n,{get:()=>s[n],enumerable:!(r=Et(s,n))||r.enumerable});return t};var $t=(t,s,e)=>(e=t!=null?St(vt(t)):{},nt(s||!t||!t.__esModule?re(e,"default",{value:t,enumerable:!0}):e,t)),Lt=t=>nt(re({},"__esModule",{value:!0}),t);var tr={};T(tr,{AzureDevOps:()=>W,AzureDevopsUtils:()=>Pe,Bitbucket:()=>H,BitbucketServer:()=>J,BitbucketServerUtils:()=>qe,BitbucketUtils:()=>we,GitHub:()=>K,GitHubUtils:()=>Se,GitLab:()=>X,GitLabUtils:()=>Ee,GitProviderUtils:()=>De,Jira:()=>Z,JiraServer:()=>ee,JiraUtils:()=>Ce,Trello:()=>te,TrelloUtils:()=>ve,Utils:()=>er,default:()=>Zs});module.exports=Lt(tr);var S=100;var at=$t(require("node-fetch")),ot=globalThis.fetch||at.default;var Gt=async t=>{let s=t.headers.get("content-type")||"",e=null;if(s.startsWith("application/json")){let n=await t.text();e=n.trim().length>0?JSON.parse(n):null}else if(s.startsWith("text/")||s==="")e=await t.text();else if(s.startsWith("application/vnd.github.raw+json"))e=await t.arrayBuffer();else throw new Error(`Unsupported content-type: ${s}`);let r={body:e,headers:Object.fromEntries(t.headers.entries()),status:t.status,statusText:t.statusText};if(!t.ok){let n=new Error(t.statusText);throw Object.assign(n,{response:r}),n}return r},Ue=t=>async({url:s,...e})=>{let r=await t(s,e);return Gt(r)};var $e=(t,s=!1)=>t.name==="fetch"||s;var v=class{constructor(s){let e=(s==null?void 0:s.request)||ot;this.config={...s,request:$e(e,s==null?void 0:s.forceIsFetch)?Ue(e):e}}updateConfig(s){this.config={...this.config,...s,request:s.request&&$e(s.request,(s==null?void 0:s.forceIsFetch)??this.config.forceIsFetch)?Ue(s.request):this.config.request}}},L=class extends v{};var R=(t,s)=>{let e={};return t&&(e.Authorization=`${s?"Basic":"Bearer"} ${t}`),e},it=t=>t?t.reduce((s,e)=>(s[e]=!0,s),{}):void 0,N=(t,s,e)=>!t||s.some(r=>t[r])?e:"";var w=(t,s={})=>R(s.token||t.token,s.isPAT||t.isPAT),ut=t=>t.url.replace("/_apis/git/repositories/","/_git/").replace(`/${t.repository.project.id}/`,`/${encodeURIComponent(t.repository.project.name)}/`).replace(`/${t.repository.id}/`,`/${encodeURIComponent(t.repository.name)}/`).replace("/pullRequests/","/pullrequest/");var lt={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},Q=t=>!t||t.length===0?null:t.reduce((s,e)=>lt[e.state]>lt[s]?e.state:s,"APPROVED");var pt="https://app.vssps.visualstudio.com/_apis",q="https://dev.azure.com",At={active:"OPEN",completed:"MERGED",abandoned:"CLOSED"},Tt={10:"APPROVED",5:"APPROVED",0:"REVIEW_REQUESTED",[-5]:"CHANGES_REQUESTED",[-10]:"CHANGES_REQUESTED"},Le=t=>({id:t.id,name:t.displayName,username:t.uniqueName||t.displayName,email:null,avatarUrl:t.imageUrl,url:null}),ae=t=>t.startsWith("refs/heads/")?t.replace("refs/heads/",""):t,ne=(t,s)=>{var r;let e=s.reviewers.filter(n=>n.vote!==0).map(n=>({reviewer:Le(n),state:Tt[n.vote]||"REVIEW_REQUESTED"}));return{id:s.pullRequestId.toString(),title:s.title,number:s.codeReviewId,state:At[s.status],isDraft:s.isDraft,commentCount:null,upvoteCount:null,author:Le(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:t},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:ae(s.targetRefName),oid:s.lastMergeTargetCommit.commitId},headRef:{name:ae(s.sourceRefName),oid:s.lastMergeSourceCommit.commitId},url:ut(s),assignees:s.reviewers.map(Le),reviews:e,reviewDecision:Q(e),additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",labels:((r=s.labels)==null?void 0:r.map(n=>({color:null,description:null,id:n.id,name:n.name})))??[],permissions:null}},dt=(t,s)=>({id:s.id,name:s.name,namespace:t,project:s.project.name,webUrl:s.webUrl,httpsUrl:s.remoteUrl,sshUrl:s.sshUrl,defaultBranch:s.defaultBranch?{name:ae(s.defaultBranch)}:null,permission:null}),Ot=(t,s)=>{var i,u;let e=t.fields,r=e["System.AssignedTo"],n=e["System.State"],o=e["System.WorkItemType"],a;return n&&o&&(a=(i=s[o])==null?void 0:i[n]),{id:t.id.toString(),number:t.id.toString(),title:e["System.Title"],commentCount:e["System.CommentCount"],author:{avatarUrl:e["System.CreatedBy"]._links.avatar.href,email:null,id:e["System.CreatedBy"].id,name:e["System.CreatedBy"].uniqueName,username:e["System.CreatedBy"].displayName,url:null},closedDate:e["Microsoft.VSTS.Common.ClosedDate"]?new Date(e["Microsoft.VSTS.Common.ClosedDate"]):null,createdDate:new Date(e["System.CreatedDate"]),updatedDate:new Date(e["System.ChangedDate"]),url:t._links.html.href,assignees:r?[{avatarUrl:r._links.avatar.href,email:null,id:r.id,name:r.uniqueName,username:r.displayName,url:null}]:[],description:null,state:{name:(a==null?void 0:a.title)||n,color:null},type:e["System.WorkItemType"],repository:null,upvoteCount:0,labels:((u=t.fields["System.Tags"])==null?void 0:u.split(";").map(l=>({color:null,description:null,id:null,name:l.trim()})))??[]}},W=class extends v{async getCurrentUser(s={},e={}){if(e.isPAT||this.config.isPAT)throw new Error("Azure DevOps does not support PATs for this function.");let r=await this.config.request({url:`${pt}/profile/profiles/me`,headers:w(this.config,e)});return{data:{id:r.body.id,name:r.body.displayName,username:r.body.displayName,email:r.body.emailAddress,avatarUrl:null,url:null}}}async getCurrentUserForInstance(s,e={}){let n=(await this.config.request({url:`${q}/${encodeURIComponent(s.namespace)}/_apis/ConnectionData`,headers:w(this.config,e)})).body.authorizedUser;if(n.providerDisplayName==="Anonymous")throw new Error("Current user not found.");return{data:{id:n.id,name:n.providerDisplayName,username:n.providerDisplayName,email:n.properties.Account.$value,avatarUrl:null}}}async getUserForCommit(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:`${q}/${encodeURIComponent(s.repo.namespace)}/${encodeURIComponent(s.repo.project)}/_apis/git/repositories/${encodeURIComponent(s.repo.name)}/commits/${s.oid}`,headers:w(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:`${pt}/accounts?memberId=${s.userId}&api-version=6.0`,headers:w(this.config,e)})).body.value.map(n=>({id:n.accountId,name:n.accountName}))}}async getAzureProjects(s,e={}){let r=new URL(`${q}/${encodeURIComponent(s.namespace)}/_apis/projects`);r.searchParams.set("$top",S.toString()),s.cursor&&r.searchParams.set("$skip",s.cursor);let n=await this.config.request({url:r.toString(),headers:w(this.config,e)}),o=n.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!o,endCursor:o||null},data:n.body.value.map(a=>({id:a.id,name:a.name,namespace:s.namespace}))}}async getAzureProjectScopeDescriptor(s,e={}){let{namespace:r,projectId:n}=s;return{data:{scope:(await this.config.request({url:`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_apis/graph/descriptors/${n}?api-version=6.0`,headers:w(this.config,e)})).body.value}}}async getAzureGraphAccountsForAzureProject(s,e={}){let{namespace:r,projectScopeDescriptor:n,cursor:o}=s,a=new URL(`https://vssps.dev.azure.com/${encodeURIComponent(r)}/_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:w(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:r}=s,n=await this.config.request({url:r.storageKeyURL,headers:w(this.config,e)});return{data:{avatarUrl:r.avatarUrl,email:r.email,id:n.body.value,name:r.name,username:r.username,url:null}}}async getAccountsFromAzureGraphAccounts(s,e={}){let r=[];for(let n of s.azureGraphAccounts){let o=await this.getAccountFromAzureGraphAccount({azureGraphAccount:n},e);r.push(o.data)}return{data:r}}async getRepo(s,e={}){if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let r=await this.config.request({url:`${q}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories/${encodeURIComponent(s.name)}`,headers:w(this.config,e)});return{data:dt(s.namespace,r.body)}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);r.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:r,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:`${q}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/git/repositories`,headers:w(this.config,e)})).body.value.map(n=>dt(s.namespace,n))}}async getRefs(s,e,r={}){if(!e.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let n=new URL(`${q}/${encodeURIComponent(e.repo.namespace)}/${encodeURIComponent(e.repo.project)}/_apis/git/repositories/${encodeURIComponent(e.repo.name)}/refs`);n.searchParams.set("filter",s),n.searchParams.set("$top",S.toString()),e.cursor&&n.searchParams.set("continuationToken",e.cursor);let o=await this.config.request({url:n.toString(),headers:w(this.config,r)}),a=o.headers["x-ms-continuationtoken"];return{pageInfo:{hasNextPage:!!a,endCursor:a||null},data:o.body.value.map(i=>({name:ae(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={},r=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||q}/${encodeURIComponent(o.namespace)}/${encodeURIComponent(o.project||"")}/_apis/git/repositories/${encodeURIComponent(o.name)}/pullRequests?${l}&%24top=${r}&%24skip=${(u-1)*r}`,headers:w(this.config,e)})}async getPullRequestsForRepo(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=>ne(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:r}=s||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForRepoBase({repo:o,...s},e)).body.value.forEach(i=>{n.push(ne(o.namespace,i))})}catch(a){if(a.statusCode!==404&&a.statusCode!==401)throw a}})),{data:n}}async getPullRequestsForProjectBase(s,e={},r=100){let{namespace:n,project:o,page:a,assigneeLogins:i,authorLogin:u}=s,l=a||1,p=new URL(`${e.baseUrl||q}/${encodeURIComponent(n)}/${encodeURIComponent(o)}/_apis/git/pullRequests`);return p.searchParams.set("searchCriteria.status","1"),p.searchParams.set("$top",r.toString()),p.searchParams.set("$skip",((l-1)*r).toString()),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:w(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=>ne(s.namespace,a))}}async getPullRequestsForProjects(s,e={}){let{projects:r}=s||{},n=[];return await Promise.all(r.map(async o=>{try{(await this.getPullRequestsForProjectBase({...o,...s},e)).body.value.forEach(i=>{n.push(ne(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:r,project:n,name:o},pullRequestId:a}=s,i=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}?includeCommits=true?api-version=6.0`,headers:{...w(this.config,e)}});if(!i.body.mergeStatus)throw new Error("Could not fetch pull request");return{data:i.body.mergeStatus}}async updatePullRequest(s,e,r,n){let{namespace:o,project:a,name:i}=s;return await this.config.request({method:"PATCH",url:`${n.baseUrl||q}/${encodeURIComponent(o)}/${encodeURIComponent(a||"")}/_apis/git/repositories/${i}/pullrequests/${e}?api-version=6.0`,body:r,headers:{...w(this.config,n),"Content-Type":"application/json"}})}async closePullRequest(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n}=s,o={status:"abandoned"};if(!(await this.updatePullRequest(r,n,JSON.stringify(o),e)).body.status)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n,expectedSourceSha:o,mergeStrategy:a}=s,i;switch(a){case"MERGE_COMMIT":{i="noFastForward";break}case"REBASE":{i="rebase";break}case"REBASE_THEN_MERGE_COMMIT":{i="rebaseMerge";break}case"SQUASH":{i="squash";break}}let u={completionOptions:{mergeStrategy:i},lastMergeSourceCommit:{commitId:o},status:"completed"};if(!(await this.updatePullRequest(r,n,JSON.stringify(u),e)).body.status)throw new Error("Could not merge pull request")}async addPullRequestLabel(s,e={}){let{repo:{namespace:r,project:n,name:o},pullRequestId:a,labelName:i}=s;if(!n)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let u={name:i};if(!(await this.config.request({method:"POST",url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}/labels?api-version=6.0`,body:JSON.stringify(u),headers:{...w(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request label")}async removePullRequestLabel(s,e={}){let{repo:{namespace:r,project:n,name:o},pullRequestId:a,labelNameOrId:i}=s;if(!n)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');await this.config.request({method:"DELETE",url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}/labels/${encodeURIComponent(i)}?api-version=6.0`,headers:{...w(this.config,e)}})}async setPullRequestAsDraft(s,e={}){if(!s.repo.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{repo:r,pullRequestId:n,isDraft:o}=s,a={isDraft:o};if(!(await this.updatePullRequest(r,n,JSON.stringify(a),e)).body.status)throw new Error("Could not set the pull request as draft")}async addPullRequestReviewer(s,e={}){if(!s.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:a,reviewerId:i,isRequired:u}=s,l={id:i,isRequired:u};if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}/reviewers/${i}?api-version=6.0`,body:JSON.stringify(l),headers:{...w(this.config,e),"Content-Type":"application/json"}})).body.id)throw new Error("Could not add pull request reviewer")}async removePullRequestReviewer(s,e={}){if(!s.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:a,reviewerId:i}=s;await this.config.request({method:"DELETE",url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/git/repositories/${o}/pullrequests/${a}/reviewers/${i}?api-version=6.0`,headers:{...w(this.config,e),Accept:"application/json"}})}async getIssuesForAzureProject(s,e={}){let{page:r,assigneeLogins:n,authorLogin:o,mentionLogin:a,statusByWorkItemIdByStatusId:i}=s||{},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("'","''")}'`),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||q}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/wiql?api-version=6.0`,body:JSON.stringify({query:d}),method:"POST",headers:{...w(this.config,e),"Content-Type":"application/json"}}),g=c.body.workItems.slice((u-1)*l,l*u).map(f=>f.id);if(g.length==0)return{pageInfo:{hasNextPage:!1,nextPage:null},data:[]};let m=await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(s.namespace)}/${encodeURIComponent(s.project)}/_apis/wit/workitemsbatch?api-version=6.0`,body:JSON.stringify({ids:g,$expand:"Links"}),method:"POST",headers:{...w(this.config,e),"Content-Type":"application/json"}});return{pageInfo:{hasNextPage:c.body.workItems.length>l*u,nextPage:u+1},data:m.body.value.map(f=>Ot(f,i||{}))}}async updateIssue(s,e,r,n,o={}){return await this.config.request({method:"PATCH",url:`${o.baseUrl||q}/${encodeURIComponent(s)}/${encodeURIComponent(e||"")}/_apis/wit/workitems/${r}?api-version=6.0`,body:JSON.stringify(n),headers:{...w(this.config,o),"Content-Type":"application/json-patch+json"}})}async setIssueStatus(s,e={}){var l;if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n,issueId:o,status:a}=s,i=[{op:"add",path:"/fields/System.State",value:a}];if(!((l=(await this.updateIssue(r,n,o,i,e)).body.fields)!=null&&l["System.State"]))throw new Error("Could not set issue status")}async setIssueAssignee(s,e={}){var l;if(!s.project)throw new Error('Azure DevOps requires a "project" (name or ID) for this function.');let{namespace:r,project:n,issueId:o,assigneeNameOrEmail:a}=s,i=[{op:"add",path:"/fields/System.AssignedTo",value:a??""}];if(!((l=(await this.updateIssue(r,n,o,i,e)).body.fields)!=null&&l["System.State"]))throw new Error("Could not set issue assignee")}async setIssueLabels(s,e={}){var l;let{namespace:r,project:n,issueId:o,tagNames:a}=s,i=[{op:"replace",path:"/fields/System.Tags",value:a.join(";")}];if(!((l=(await this.updateIssue(r,n,o,i,e)).body.fields)!=null&&l["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:r,project:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/workitemtypes?api-version=6.0`,headers:{...w(this.config,e)}})).body.value}}async getLabelsForProject(s,e={}){let{namespace:r,project:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||q}/${encodeURIComponent(r)}/${encodeURIComponent(n||"")}/_apis/wit/tags?api-version=6.0`,headers:{...w(this.config,e)}})).body.value.map(a=>({color:null,description:null,id:a.id,name:a.name}))}}};var C=(t,s={})=>R(s.token||t.token,s.isPAT||t.isPAT);var U="https://api.bitbucket.org/2.0",xt={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},gt=t=>({id:t.uuid,name:t.display_name||t.nickname,username:t.nickname||t.display_name,email:null,avatarUrl:t.links.avatar.href,url:t.links.html.href}),ct=t=>{var s,e;return{id:t.uuid,namespace:t.workspace.slug,name:t.slug,webUrl:t.links.html.href,httpsUrl:((s=t.links.clone.find(r=>r.name==="https"))==null?void 0:s.href)??null,sshUrl:((e=t.links.clone.find(r=>r.name==="ssh"))==null?void 0:e.href)??null,defaultBranch:{name:t.mainbranch.name},permission:null}},Ae=t=>{let s=t.id;return{id:s.toString(),title:t.title,number:s,state:xt[t.state],isDraft:!1,commentCount:t.comment_count,upvoteCount:null,author:gt(t.author),createdDate:new Date(t.created_on),updatedDate:new Date(t.updated_on),closedDate:null,mergedDate:null,repository:{id:t.destination.repository.uuid,name:t.destination.repository.name,owner:{login:t.destination.repository.full_name.split("/")[0]},remoteInfo:null},headCommit:{buildStatuses:null},baseRef:{name:t.destination.branch.name,oid:t.destination.commit.hash},headRef:{name:t.source.branch.name,oid:t.source.commit.hash},url:t.links.html.href,assignees:null,reviews:null,reviewDecision:null,additions:null,deletions:null,fileCount:null,commitCount:null,headRepository:null,mergeableState:"UNKNOWN",permissions:null}},H=class extends v{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 r=await this.config.request({url:`${U}/user`,headers:C(this.config,e)});return{data:gt(r.body)}}async getUserForCommit(s,e={}){var a;let n=(await this.config.request({url:`${U}/repositories/${s.repo.namespace}/${s.repo.name}/commit/${s.oid}`,headers:C(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 r=await this.config.request({url:`${U}/repositories/${s.namespace}/${s.name}`,headers:C(this.config,e)});return{data:ct(r.body)}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);r.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:r,errors:n}}async getReposForCurrentUser(s={},e={}){let r=new URL(`${U}/repositories`);r.searchParams.set("role","member"),r.searchParams.set("pagelen",S.toString()),s.cursor&&r.searchParams.set("after",s.cursor);let n=await this.config.request({url:r.toString(),headers:C(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(ct)}}async getBranches(s,e={}){var a;let r=new URL(`${U}/repositories/${s.repo.namespace}/${s.repo.name}/refs/branches`);r.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),r.searchParams.set("pagelen",S.toString());let n=await this.config.request({url:r.toString(),headers:C(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 r=new URL(`${U}/repositories/${s.repo.namespace}/${s.repo.name}/refs/tags`);r.searchParams.set("pagelen",S.toString()),s.cursor&&r.searchParams.set("page",s.cursor);let n=await this.config.request({url:r.toString(),headers:C(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 r=new URL(`${U}/pullrequests/${s.userId}`);r.searchParams.set("page",((a=s.page)==null?void 0:a.toString())||"1"),r.searchParams.set("pagelen","50");let n=await this.config.request({url:r.toString(),headers:C(this.config,e)}),o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:n.body.values.map(Ae)}}async getPullRequestsForRepoBase(s,e={}){var n;let r=new URL(`${U}/repositories/${encodeURI(s.repo.namespace)}/${encodeURI(s.repo.name)}/pullrequests?state=OPEN`);return r.searchParams.set("page",((n=s.page)==null?void 0:n.toString())||"1"),r.searchParams.set("pagelen","50"),await this.config.request({url:r.toString(),headers:C(this.config,e)})}async getPullRequestsForRepo(s,e={}){let r=[],n=await this.getPullRequestsForRepoBase(s,e);n.body.values.forEach(a=>{if(s.authorLogin&&a.author.uuid!==s.authorLogin)return null;r.push(Ae(a))});let o=!!n.body.next;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.page+1:null},data:r}}async getPullRequestsForRepos(s,e={}){let r=[];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;r.push(Ae(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async closePullRequest(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:o}=s;if(!(await this.config.request({method:"POST",url:`${U}/repositories/${r}/${n}/pullrequests/${o}/decline`,headers:C(this.config,e)})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:o,mergeStrategy:a}=s,i;switch(a){case"MERGE_COMMIT":{i="merge_commit";break}case"FAST_FORWARD":{i="fast_forward";break}case"SQUASH":{i="squash";break}}let u={merge_strategy:i,type:"pullrequest"};if(!(await this.config.request({method:"POST",url:`${U}/repositories/${r}/${n}/pullrequests/${o}/merge`,body:JSON.stringify(u),headers:{...C(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not merge pull request")}async setPullRequestReviewers(s,e={}){let{repo:{namespace:r,name:n},pullRequestId:o,reviewerUsernames:a}=s,i={reviewers:a.map(l=>({username:l}))};if(!(await this.config.request({method:"PUT",url:`${U}/repositories/${r}/${n}/pullrequests/${o}`,body:JSON.stringify(i),headers:{...C(this.config,e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var mt=t=>({name:t.displayName,email:t.emailAddress,avatarUrl:null,id:t.id.toString(),username:t.name,url:t.links.self[0].href}),Te=t=>{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"},r=t.reviewers.map(m=>({reviewer:mt(m.user),state:e[m.status]})),n=((u=t.toRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:u.href)??null,o=((l=t.toRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:l.href)??null;o||(o=((p=t.toRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:p.href)??null);let a=((d=t.fromRef.repository.links.clone.find(m=>m.name==="ssh"))==null?void 0:d.href)??null,i=((c=t.fromRef.repository.links.clone.find(m=>m.name==="https"))==null?void 0:c.href)??null;return i||(i=((g=t.fromRef.repository.links.clone.find(m=>m.name==="http"))==null?void 0:g.href)??null),{id:t.id.toString(),number:t.id,title:t.title,url:t.links.self[0].href,state:s[t.state],isDraft:!1,createdDate:new Date(t.createdDate),updatedDate:new Date(t.updatedDate),closedDate:t.closedDate?new Date(t.closedDate):null,mergedDate:t.state=="MERGED"&&t.closedDate?new Date(t.closedDate):null,baseRef:{name:t.toRef.displayId,oid:t.toRef.latestCommit},headRef:{name:t.fromRef.displayId,oid:t.fromRef.latestCommit},commentCount:t.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:mt(t.author.user),assignees:null,reviews:r,reviewDecision:Q(r),repository:{id:t.toRef.repository.id.toString(),name:t.toRef.repository.name,owner:{login:t.toRef.repository.project.name},remoteInfo:o&&n?{cloneUrlHTTPS:o,cloneUrlSSH:n}:null},headRepository:{id:t.fromRef.repository.id.toString(),name:t.fromRef.repository.name,owner:{login:t.fromRef.repository.project.name},remoteInfo:i&&a?{cloneUrlHTTPS:i,cloneUrlSSH:a}:null},headCommit:null,mergeableState:"UNKNOWN",permissions:null}},J=class extends L{getBaseUrl(s){let e=s.baseUrl||this.config.baseUrl;if(!e)throw new Error('Bitbucket Server requires "baseUrl"');return e}getRequestHeaders(s){return R(s.token||this.config.token)}async getRepo(s,e={}){var n,o,a;let r=await this.config.request({url:`${this.getBaseUrl(e)}/projects/${s.namespace}/repos/${s.name}`,headers:this.getRequestHeaders(e)});return{data:{id:r.body.id.toString(),namespace:r.body.project.key,name:r.body.slug,webUrl:((n=r.body.links.self[0])==null?void 0:n.href)??null,httpsUrl:((o=r.body.links.clone.find(i=>i.name==="https"))==null?void 0:o.href)??null,sshUrl:((a=r.body.links.clone.find(i=>i.name==="ssh"))==null?void 0:a.href)??null,defaultBranch:null,permission:null}}}async getRepos(s,e={}){let r=[],n=[];return await Promise.all(s.map(async o=>{try{let a=await this.getRepo(o,e);r.push(a.data)}catch(a){n.push({input:o,error:a})}})),{data:r,errors:n}}async getPullRequestsForRepoBase(s,e={}){var n;let r=new URL(`${this.getBaseUrl(e)}/projects/${encodeURI(s.repo.namespace)}/repos/${encodeURI(s.repo.name)}/pull-requests?state=OPEN`);return r.searchParams.set("start",((n=s.page)==null?void 0:n.toString())||"0"),r.searchParams.set("limit","50"),await this.config.request({url:r.toString(),headers:this.getRequestHeaders(e)})}async getPullRequestsForRepo(s,e={}){let r=[],n=await this.getPullRequestsForRepoBase(s,e);n.body.values.forEach(a=>{if(s.authorLogin&&a.author.user.name!==s.authorLogin)return null;r.push(Te(a))});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(s,e={}){let r=[];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;r.push(Te(a))})}catch(o){if(o.statusCode!==404&&o.statusCode!==401)throw o}})),{data:r}}async getPullRequestsForCurrentUser(s,e={}){var a;let r=new URL(`${this.getBaseUrl(e)}/dashboard/pull-requests`);r.searchParams.set("state","OPEN"),r.searchParams.set("start",((a=s.page)==null?void 0:a.toString())||"0"),r.searchParams.set("limit","50");let n=await this.config.request({url:r.toString(),headers:this.getRequestHeaders(e)}),o=n.body.values.length!==0;return{pageInfo:{hasNextPage:o,nextPage:o?n.body.start+n.body.values.length:null},data:n.body.values.map(Te)}}async closePullRequest(s,e){let{repo:{namespace:r,name:n},pullRequestId:o,version:a}=s;if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${o}/decline`,body:JSON.stringify({version:a}),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not close pull request")}async mergePullRequest(s,e){let{repo:{namespace:r,name:n},pullRequestId:o,mergeStrategyId:a,version:i}=s;if(!(await this.config.request({method:"POST",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${o}/merge`,body:JSON.stringify({strategyId:a,version:i}),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{repo:{namespace:r,name:n},pullRequestId:o,reviewerUsernames:a,version:i}=s,u={reviewers:a.map(p=>({user:{name:p}})),version:i};if(!(await this.config.request({method:"PUT",url:`${this.getBaseUrl(e)}/projects/${r}/repos/${n}/pull-requests/${o}`,body:JSON.stringify(u),headers:{...this.getRequestHeaders(e),"Content-Type":"application/json"}})).body.title)throw new Error("Could not set pull request reviewers")}};var ue="https://api.github.com",kt=`${ue}/graphql`,le=`
|
|
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
|
+
`,_t=`
|
|
10
10
|
... on CheckRun {
|
|
11
11
|
completedAt
|
|
12
12
|
conclusion
|
|
@@ -20,16 +20,16 @@ color
|
|
|
20
20
|
description
|
|
21
21
|
id
|
|
22
22
|
name
|
|
23
|
-
`,
|
|
23
|
+
`,ht=t=>{if(t.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.")},Nt=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),ht(e),ie.test(e)&&(e=e.replace(ie,"")),`${e}/api/graphql`):kt},Oe=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),ht(e),ie.test(e)&&(e=e.replace(ie,"")),`${e}/api/v3`):ue},b=(t,s,e)=>{let r=R(e.token||t.token);return r["X-Github-Next-Global-ID"]="1",r["Content-Type"]="application/json",r.Accept="application/vnd.github.merge-info-preview+json",t.request({url:Nt(t,e),method:"POST",headers:r,body:JSON.stringify(s)})},Qt={user:!0,"user:email":!0,"read:user":!0},O=t=>t.some(s=>Qt[s]),$=(t=!1,s=!1,e)=>`
|
|
24
24
|
__typename
|
|
25
|
-
${
|
|
26
|
-
${
|
|
27
|
-
${
|
|
28
|
-
${
|
|
29
|
-
${s?
|
|
30
|
-
${
|
|
31
|
-
${
|
|
32
|
-
`,
|
|
25
|
+
${N(e,["graphQLId"],"id")}
|
|
26
|
+
${N(e,["id"],"databaseId")}
|
|
27
|
+
${N(e,["name"],"name")}
|
|
28
|
+
${N(e,["name","username"],"login")}
|
|
29
|
+
${s?N(e,["email"],"email"):""}
|
|
30
|
+
${N(e,["avatarUrl"],`avatarUrl${t?"(size: $avatarSize)":""}`)}
|
|
31
|
+
${N(e,["url"],"url")}
|
|
32
|
+
`,Ft=(t=!1)=>`
|
|
33
33
|
latestReviews(first: 100) {
|
|
34
34
|
nodes {
|
|
35
35
|
author {
|
|
@@ -40,14 +40,14 @@ latestReviews(first: 100) {
|
|
|
40
40
|
state
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
`,
|
|
43
|
+
`,ft=(t=!1)=>`
|
|
44
44
|
__typename
|
|
45
45
|
id
|
|
46
46
|
databaseId
|
|
47
47
|
login
|
|
48
48
|
avatarUrl${t?"(size: $avatarSize)":""}
|
|
49
49
|
url
|
|
50
|
-
`,
|
|
50
|
+
`,de=(t,s=!1,e)=>`
|
|
51
51
|
id
|
|
52
52
|
databaseId
|
|
53
53
|
number
|
|
@@ -58,7 +58,7 @@ author {
|
|
|
58
58
|
${$(!1,s)}
|
|
59
59
|
}
|
|
60
60
|
... on Bot {
|
|
61
|
-
${
|
|
61
|
+
${ft(!1)}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
commits(last: 1) {
|
|
@@ -71,7 +71,7 @@ commits(last: 1) {
|
|
|
71
71
|
contexts(first: 100) {
|
|
72
72
|
totalCount
|
|
73
73
|
nodes {
|
|
74
|
-
${e?
|
|
74
|
+
${e?_t:""}
|
|
75
75
|
... on StatusContext {
|
|
76
76
|
context
|
|
77
77
|
createdAt
|
|
@@ -146,7 +146,7 @@ reviewRequests(first: 100) {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
|
-
${e?
|
|
149
|
+
${e?Ft(s):""}
|
|
150
150
|
additions
|
|
151
151
|
deletions
|
|
152
152
|
changedFiles
|
|
@@ -161,7 +161,7 @@ labels(first: 100) {
|
|
|
161
161
|
}
|
|
162
162
|
}
|
|
163
163
|
viewerCanMergeAsAdmin
|
|
164
|
-
`,
|
|
164
|
+
`,Bt=(t=!1)=>`
|
|
165
165
|
id
|
|
166
166
|
databaseId
|
|
167
167
|
title
|
|
@@ -170,7 +170,7 @@ author {
|
|
|
170
170
|
${$(!1,t)}
|
|
171
171
|
}
|
|
172
172
|
... on Bot {
|
|
173
|
-
${
|
|
173
|
+
${ft(!1)}
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
closedAt
|
|
@@ -206,7 +206,7 @@ labels(first: 100) {
|
|
|
206
206
|
${pe}
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
-
`,
|
|
209
|
+
`,jt={"-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"},Mt=new RegExp('(([^\\s]+:)?\\"(?:[^\\"\\\\]|\\\\.)*\\"?)|([^\\"\\s]+)',"g"),xe=t=>{let s=[];return(t.match(Mt)??[]).forEach(r=>{if(r.includes(":")&&r!="is:closed"){let n=r.split(":")[0];jt[n]&&s.push(r)}}),s},ke=(t,s,e,r,n=!1,o=!1)=>{let a=t==="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 {
|
|
@@ -215,18 +215,18 @@ query SearchIssuesOrPullRequests($query: String! $after: String) {
|
|
|
215
215
|
}
|
|
216
216
|
nodes {
|
|
217
217
|
... on ${a?"Issue":"PullRequest"} {
|
|
218
|
-
${a?
|
|
218
|
+
${a?Bt(r):de(n,r,o)}
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
|
-
}`,variables:{query:`is:${t} is:open ${s}`,after:e}}},
|
|
222
|
+
}`,variables:{query:`is:${t} is:open ${s}`,after:e}}},zt="Field 'isDraft' doesn't exist on type 'PullRequest'",ce=(t=[])=>t.some(s=>(s==null?void 0:s.message)===zt),Wt=/@@ -(\d+)(?:,\d+ | )\+(\d+)(?:,\d+ | )@@(?:\\n)?/,Ht=`
|
|
223
223
|
\
|
|
224
|
-
+`,
|
|
224
|
+
+`,Rt=(t,s,e,r)=>{let n=Wt.exec(t);if(!n||!n[0]||!n[1])return[];let o=parseInt(n[1],10),a=parseInt(n[2],10),i=t.replace(Ht,`
|
|
225
225
|
+`).split(`
|
|
226
226
|
`).slice(1),u=o-1,l=a-1,p=i.map(g=>{let m,f;switch(g[0]){case"-":{m="DELETED",u+=1,f=`${g.slice(1)}
|
|
227
227
|
`;break}case"+":{m="ADDED",l+=1,f=`${g.slice(1)}
|
|
228
228
|
`;break}default:m="UNMODIFIED",l+=1,u+=1,f=`${g}
|
|
229
|
-
`}return{line:f,oldLineNumber:m!=="ADDED"?u:null,newLineNumber:m!=="DELETED"?l:null,type:m}}),d=e,c=s;if(d!==null&&c!==null&&r!==null&&d<c){let g=0,m=p.length,f=r==="LEFT"?"oldLineNumber":"newLineNumber";for(let I=0;I<p.length;I++){let P=p[I][f];P===d?g=I:P===c&&(m=I)}p=p.slice(g,m+1)}return p};var
|
|
229
|
+
`}return{line:f,oldLineNumber:m!=="ADDED"?u:null,newLineNumber:m!=="DELETED"?l:null,type:m}}),d=e,c=s;if(d!==null&&c!==null&&r!==null&&d<c){let g=0,m=p.length,f=r==="LEFT"?"oldLineNumber":"newLineNumber";for(let I=0;I<p.length;I++){let P=p[I][f];P===d?g=I:P===c&&(m=I)}p=p.slice(g,m+1)}return p};var _e=`
|
|
230
230
|
id
|
|
231
231
|
databaseId
|
|
232
232
|
owner {
|
|
@@ -239,10 +239,10 @@ defaultBranchRef {
|
|
|
239
239
|
name
|
|
240
240
|
}
|
|
241
241
|
viewerPermission
|
|
242
|
-
`,
|
|
242
|
+
`,Fe={__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"},Jt={APPROVED:"APPROVED",CHANGES_REQUESTED:"CHANGES_REQUESTED",COMMENTED:"COMMENTED",REVIEW_REQUESTED:"REVIEW_REQUESTED"},Kt={MERGEABLE:"MERGEABLE",CONFLICTING:"CONFLICTS",UNKNOWN:"UNKNOWN"},Vt={BEHIND:"BEHIND",BLOCKED:"BLOCKED",UNKNOWN:"UNKNOWN_AND_BLOCKED",UNSTABLE:"UNSTABLE",CLEAN:null,DIRTY:null,DRAFT:null,HAS_HOOKS:null},Xt={OPEN:"OPEN",CLOSED:"CLOSED"},Yt=["ADMIN","MAINTAIN","TRIAGE","WRITE"],Be=t=>({color:t.color,description:t.description,graphQLId:t.id,id:null,name:t.name}),Ne=t=>({id:t.databaseId.toString(),graphQLId:t.id,namespace:t.owner.login,name:t.name,webUrl:t.url,httpsUrl:t.url.endsWith(".git")?t.url:`${t.url}.git`,sshUrl:t.sshUrl,defaultBranch:t.defaultBranchRef,permission:t.viewerPermission}),Zt={OPEN:"OPEN",CLOSED:"CLOSED",MERGED:"MERGED"},es={id:!0,graphQLId:!0,name:!0,username:!0,email:!0,avatarUrl:!0,url:!0},G=(t,s=es)=>{let e={};return s.id&&(e.id=t.databaseId.toString()),s.graphQLId&&(e.graphQLId=t.id),s.name&&(e.name=t.name??t.login),s.username&&(e.username=t.login),s.email&&(e.email=t.email??null),s.avatarUrl&&(e.avatarUrl=t.avatarUrl),s.url&&(e.url=t.url),e},ts=(t,s)=>{let e={IN_PROGRESS:"RUNNING",PENDING:"PENDING",QUEUED:"PENDING",REQUESTED:"PENDING",WAITING:"PENDING"};return t!=="COMPLETED"?e[t]:{ACTION_REQUIRED:"ACTION_REQUIRED",CANCELLED:"CANCELLED",FAILURE:"FAILED",NEUTRAL:null,SKIPPED:"SKIPPED",STALE:"FAILED",STARTUP_FAILURE:"FAILED",SUCCESS:"SUCCESS",TIMED_OUT:"ERROR"}[s]},ss=t=>({ERROR:"ERROR",EXPECTED:"PENDING",FAILURE:"FAILED",PENDING:"PENDING",SUCCESS:"SUCCESS"})[t],Qe=t=>{var a,i,u,l,p,d,c,g,m,f,I;let s=null;t.author?s=(t.author.__typename==="Bot",t.author):s=Fe;let e=(((a=t.reviewRequests)==null?void 0:a.nodes)||[]).filter(h=>!h.asCodeOwner),r=(i=t.headRepository)==null?void 0:i.url;r&&!r.endsWith(".git")&&(r=`${r}.git`);let n=(u=t.repository)==null?void 0:u.url;n&&!n.endsWith(".git")&&(n=`${n}.git`);let o=e.filter(h=>h.requestedReviewer&&"__typename"in h.requestedReviewer).map(h=>({reviewer:G(h.requestedReviewer),state:"REVIEW_REQUESTED"})).concat((((l=t.latestReviews)==null?void 0:l.nodes)||[]).map(h=>{let P=h.author||Fe;return{reviewer:G(P),state:Jt[h.state]}}));return{id:t.databaseId.toString(),graphQLId:t.id,title:t.title,number:t.number,state:Zt[t.state],commentCount:t.comments.totalCount,upvoteCount:t.reactions.totalCount,author:s?G(s):null,createdDate:new Date(t.createdAt),isDraft:t.isDraft,repository:{id:t.repository.databaseId,graphQLId:t.repository.id,name:t.repository.name,owner:{login:t.repository.owner.login},remoteInfo:{cloneUrlHTTPS:n,cloneUrlSSH:t.repository.sshUrl}},headRepository:t.headRepository?{id:t.headRepository.databaseId,graphQLId:t.headRepository.id,name:t.headRepository.name,owner:{login:t.headRepository.owner.login},remoteInfo:{cloneUrlHTTPS:r,cloneUrlSSH:t.headRepository.sshUrl}}:null,headCommit:{buildStatuses:((c=(d=(p=t.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:ss(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:ts(h.status,h.conclusion),startedAt:h.startedAt?new Date(h.startedAt):null,stage:null,url:h.permalink}))??[]},headRef:t.headRef?{name:t.headRef.name,oid:((g=t.headRef.target)==null?void 0:g.oid)??null}:null,baseRef:t.baseRef?{name:t.baseRef.name,oid:((m=t.baseRef.target)==null?void 0:m.oid)??null}:null,url:t.url,updatedDate:new Date(t.updatedAt),closedDate:t.closedAt?new Date(t.closedAt):null,mergedDate:t.mergedAt?new Date(t.mergedAt):null,assignees:t.assignees.nodes?t.assignees.nodes.map(h=>G(h)):null,reviews:o,reviewDecision:Q(o),additions:t.additions,deletions:t.deletions,fileCount:t.changedFiles,commitCount:t.commits.totalCount,mergeableState:Vt[t.mergeStateStatus]??Kt[t.mergeable],milestone:t.milestone?je(t.milestone):null,labels:((I=(f=t.labels)==null?void 0:f.nodes)==null?void 0:I.map(Be))??[],permissions:{canMerge:Yt.includes(t.repository.viewerPermission),canMergeAndBypassProtections:t.viewerCanMergeAsAdmin}}},rs=t=>{let{comments:s,isOutdated:e,isResolved:r,originalLine:n,originalStartLine:o,startDiffSide:a}=t,{author:i,body:u,databaseId:l,id:p,path:d,publishedAt:c,url:g}=s.nodes[0];return{author:i?{avatarUrl:i.avatarUrl,email:null,name:i.login}:null,body:u,createdAt:c?new Date(c):null,diffLines:Rt(s.nodes[0].diffHunk,n,o,a),id:l,isOutdated:e,isResolved:r,graphQLId:p,filename:d,replies:s.nodes.slice(1).map(ns),url:g}},ns=t=>({author:t.author?{avatarUrl:t.author.avatarUrl,email:null,name:t.author.login}:null,body:t.body,createdAt:t.publishedAt?new Date(t.publishedAt):null,graphQLId:t.id,id:t.databaseId,url:t.url}),as=t=>{var e,r;let s=null;return t.author?s=(t.author.__typename==="Bot",t.author):s=Fe,{id:t.databaseId.toString(),graphQLId:t.id,number:t.number,title:t.title,author:G(s),commentCount:t.comments.totalCount,closedDate:t.closedAt?new Date(t.closedAt):null,createdDate:new Date(t.createdAt),description:null,state:{name:Xt[t.state],color:null},type:null,repository:{id:t.repository.databaseId,graphQLId:t.repository.id,name:t.repository.name,owner:{login:t.repository.owner.login}},url:t.url,updatedDate:new Date(t.updatedAt),assignees:t.assignees.nodes?t.assignees.nodes.map(n=>G(n)):[],upvoteCount:t.reactions.totalCount,milestone:t.milestone?je(t.milestone):null,labels:((r=(e=t.labels)==null?void 0:e.nodes)==null?void 0:r.map(Be))??[]}},je=t=>({id:t.number.toString(),graphQLId:t.id.toString(),number:t.number,title:t.title,description:t.description,isOpen:t.state=="OPEN",url:t.url,startDate:null,dueDate:t.dueOn?new Date(t.dueOn):null}),K=class extends L{constructor(){super(...arguments);this._scopesCache={};this._enterpriseVersionsCache={}}async getScopes(e){let r=e.token||this.config.token;if(!r)return[];let n=this._scopesCache[r];if(!n){let a=(await b(this.config,{query:"query { rateLimit(dryRun: true) { __typename } }"},e)).headers["x-oauth-scopes"];n=a?a.split(", "):[],this._scopesCache[r]=n}return n}async getEnterpriseVersion(e){let r=e.baseUrl||this.config.baseUrl;if(!r)return null;let n=this._enterpriseVersionsCache[r];if(!n){let o=await this.config.request({url:`${Oe(this.config,e)}/meta`,headers:R(e.token||this.config.token)});if(!o.body.installed_version)return null;n=o.body.installed_version.split(".").slice(0,3).map(a=>parseInt(a,10)),this._enterpriseVersionsCache[r]=n}return n}getEnterpriseAvatarUrlIfNeeded(e,r,n){let o=n.baseUrl||this.config.baseUrl;return!o||o.startsWith(ue)?e:r?`https://avatars.githubusercontent.com/u/e?email=${encodeURIComponent(r)}`:""}async getCurrentUser(e={},r={}){var u;if(e.fields&&!e.fields.length)throw new Error('"fields" must contain at least one field or be omitted');let n=it(e.fields),o=await this.getScopes(r),i=(u=(await b(this.config,{query:`
|
|
243
243
|
query getCurrentUser {
|
|
244
244
|
viewer {
|
|
245
|
-
${$(!1,
|
|
245
|
+
${$(!1,O(o),n)}
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
`},r)).body.data)==null?void 0:u.viewer;if(!i)throw new Error("Current user not found.");return{data:G(i,n)}}async getAccountsForRepo(e,r={}){var l,p,d,c,g,m;let n=await this.getScopes(r),{repo:{namespace:o,name:a},cursor:i}=e,u=await b(this.config,{query:`
|
|
@@ -250,7 +250,7 @@ query getAccountsForRepo($owner: String!, $name: String! $cursor: String, $first
|
|
|
250
250
|
repository(owner: $owner, name: $name) {
|
|
251
251
|
assignableUsers(first: $first, after: $cursor) {
|
|
252
252
|
nodes {
|
|
253
|
-
${$(!1,
|
|
253
|
+
${$(!1,O(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:a,cursor:i,first:
|
|
262
|
+
`,variables:{owner:o,name:a,cursor:i,first:S}},r);if(!u.body.data)throw new Error(((l=u.body.errors)==null?void 0:l[0].message)||u.statusText||"Unknown error");return{pageInfo:((d=(p=u.body.data.repository)==null?void 0:p.assignableUsers)==null?void 0:d.pageInfo)??{endCursor:null,hasNextPage:!1},data:((m=(g=(c=u.body.data.repository)==null?void 0:c.assignableUsers)==null?void 0:g.nodes)==null?void 0:m.map(f=>G(f)))??[]}}async getUserForCommit(e,r={}){var i,u;let o=(i=(await b(this.config,{query:`
|
|
263
263
|
query getUserForCommit(
|
|
264
264
|
$owner: String!
|
|
265
265
|
$name: String!
|
|
@@ -283,7 +283,7 @@ query getAccountForEmail($query: String! $avatarSize: Int) {
|
|
|
283
283
|
search(query: $query, type: USER, first: 1) {
|
|
284
284
|
nodes {
|
|
285
285
|
... on User {
|
|
286
|
-
${$(!0,
|
|
286
|
+
${$(!0,O(n))}
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
289
|
}
|
|
@@ -291,7 +291,7 @@ query getAccountForEmail($query: String! $avatarSize: Int) {
|
|
|
291
291
|
`,variables:{query:`in:email ${e.email}`,avatarSize:e.avatarSize}},r)).body.data)==null?void 0:i.search)==null?void 0:u.nodes)==null?void 0:l[0];if(!a)throw new Error("User not found.");return{data:G({...a,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,r)})}}async getAccountForUsername(e,r={}){var i;let n=await this.getScopes(r),a=(i=(await b(this.config,{query:`
|
|
292
292
|
query getUserForUsername($login: String! $avatarSize: Int) {
|
|
293
293
|
user(login: $login) {
|
|
294
|
-
${$(!0,
|
|
294
|
+
${$(!0,O(n))}
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
297
|
`,variables:{login:e.username,avatarSize:e.avatarSize}},r)).body.data)==null?void 0:i.user;if(!a)throw new Error("User not found.");return{data:G({...a,avatarUrl:this.getEnterpriseAvatarUrlIfNeeded(a.avatarUrl,a.email,r)})}}async getOrgsForCurrentUser(e={},r={}){var a,i;let n=await b(this.config,{query:`
|
|
@@ -313,22 +313,22 @@ query getOrgsForCurrentUser($cursor: String, $first: Int!) {
|
|
|
313
313
|
}
|
|
314
314
|
}
|
|
315
315
|
}
|
|
316
|
-
`,variables:{cursor:e.cursor,first:
|
|
316
|
+
`,variables:{cursor:e.cursor,first:S}},r);if(!((a=n.body.data)!=null&&a.viewer.organizations))throw new Error(((i=n.body.errors)==null?void 0:i[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(e,r={}){var o;let n=await b(this.config,{query:`
|
|
317
317
|
query getRepo($owner: String!, $name: String!) {
|
|
318
318
|
repository(owner: $owner, name: $name) {
|
|
319
|
-
${
|
|
319
|
+
${_e}
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
|
-
`,variables:{owner:e.namespace,name:e.name}},r);if(!((o=n.body.data)!=null&&o.repository))throw new Error(`Repository ${e.namespace}/${e.name} not found`);return{data:
|
|
322
|
+
`,variables:{owner:e.namespace,name:e.name}},r);if(!((o=n.body.data)!=null&&o.repository))throw new Error(`Repository ${e.namespace}/${e.name} not found`);return{data:Ne(n.body.data.repository)}}async getRepos(e,r={}){let n=e.map(({namespace:u,name:l},p)=>`
|
|
323
323
|
getRepo_${p}: repository(owner: "${u}", name: "${l}") {
|
|
324
|
-
${
|
|
324
|
+
${_e}
|
|
325
325
|
}
|
|
326
326
|
`).join(`
|
|
327
327
|
`),o=await b(this.config,{query:`
|
|
328
328
|
query batchGetRepos {
|
|
329
329
|
${n}
|
|
330
330
|
}
|
|
331
|
-
`},r);if(!o.body.data)throw new Error(o.statusText||"Unknown error");let a=[],i=[];return e.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(
|
|
331
|
+
`},r);if(!o.body.data)throw new Error(o.statusText||"Unknown error");let a=[],i=[];return e.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(Ne(p)):i.push({input:u})}),{data:a,errors:i}}async getReposForUsernames(e,r={}){var a;if(!e.usernames.length)return{pageInfo:{endCursor:null,hasNextPage:!1},data:[]};let n=await b(this.config,{query:`
|
|
332
332
|
query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
|
|
333
333
|
search(query: $query, type: REPOSITORY, first: $first, after: $cursor) {
|
|
334
334
|
pageInfo {
|
|
@@ -337,12 +337,12 @@ query getReposForUsernames($query: String!, $cursor: String, $first: Int!) {
|
|
|
337
337
|
}
|
|
338
338
|
nodes {
|
|
339
339
|
... on Repository {
|
|
340
|
-
${
|
|
340
|
+
${_e}
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
343
|
}
|
|
344
344
|
}
|
|
345
|
-
`,variables:{query:`fork:true ${e.usernames.map(i=>`user:${i}`).join(" ")}`,cursor:e.cursor,first:
|
|
345
|
+
`,variables:{query:`fork:true ${e.usernames.map(i=>`user:${i}`).join(" ")}`,cursor:e.cursor,first:S}},r);if(!n.body.data)throw new Error(((a=n.body.errors)==null?void 0:a[0].message)||n.statusText||"Unknown error");let o=n.body.data.search.nodes||[];return{pageInfo:n.body.data.search.pageInfo,data:o.map(Ne)}}async getReposForOwners(e,r={}){return this.getReposForUsernames({usernames:e.owners.filter(n=>n.username).map(n=>n.username),cursor:e.cursor},r)}async getRefs(e,r,n={}){var u;let a=(u=(await b(this.config,{query:`
|
|
346
346
|
query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: String, $first: Int!) {
|
|
347
347
|
repository(owner: $owner, name: $name) {
|
|
348
348
|
refs(refPrefix: $refPrefix first: $first after: $cursor) {
|
|
@@ -363,7 +363,7 @@ query getRefs($owner: String!, $name: String!, $refPrefix: String!, $cursor: Str
|
|
|
363
363
|
}
|
|
364
364
|
}
|
|
365
365
|
}
|
|
366
|
-
`,variables:{owner:r.repo.namespace,name:r.repo.name,refPrefix:e,cursor:r.cursor,first:
|
|
366
|
+
`,variables:{owner:r.repo.namespace,name:r.repo.name,refPrefix:e,cursor:r.cursor,first:S}},n)).body.data)==null?void 0:u.repository;if(!a)throw new Error("Repository not found.");let i=a.refs;return i?{pageInfo:i.pageInfo,data:(i.nodes||[]).map(l=>{var d;let p=(d=l.target)!=null&&d.oid?l.target:null;return{name:l.name,commit:p?{oid:p.oid,authoredDate:new Date(p.authoredDate),committedDate:new Date(p.committedDate)}:null}})}:{pageInfo:{endCursor:null,hasNextPage:!1},data:[]}}async getBranches(e,r={}){return this.getRefs("refs/heads/",e,r)}async getTags(e,r={}){return this.getRefs("refs/tags/",e,r)}async getBlame(e,r={}){var i;let o=(i=(await b(this.config,{query:`
|
|
367
367
|
query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
368
368
|
repository(owner: $owner, name: $name) {
|
|
369
369
|
object(expression: $ref) {
|
|
@@ -402,7 +402,28 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
402
402
|
}
|
|
403
403
|
}
|
|
404
404
|
}
|
|
405
|
-
`,variables:{owner:e.repo.namespace,name:e.repo.name,ref:e.ref,path:e.path}},r)).body.data)==null?void 0:i.repository;if(!o)throw new Error("Repository not found.");let a=o.object;if(!a||!("blame"in a))throw new Error("Ref not found.");if(a.blame.ranges.length===0)throw new Error("File not found.");return{data:{ranges:a.blame.ranges.map(u=>{var l;return{startingLine:u.startingLine,endingLine:u.endingLine,commit:{oid:u.commit.oid,parentOids:((l=u.commit.parents.nodes)==null?void 0:l.map(p=>p.oid))||[],authoredDate:new Date(u.commit.authoredDate),author:u.commit.author?{name:u.commit.author.name,email:u.commit.author.email,avatarUrl:u.commit.author.avatarUrl}:null,committedDate:new Date(u.commit.committedDate),committer:u.commit.committer?{name:u.commit.committer.name,email:u.commit.committer.email,avatarUrl:u.commit.committer.avatarUrl}:null,message:u.commit.message,fileCount:u.commit.changedFilesIfAvailable,additions:u.commit.additions,deletions:u.commit.deletions}}})}}}async searchPullRequests(e,r={}){var d,c;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),a=
|
|
405
|
+
`,variables:{owner:e.repo.namespace,name:e.repo.name,ref:e.ref,path:e.path}},r)).body.data)==null?void 0:i.repository;if(!o)throw new Error("Repository not found.");let a=o.object;if(!a||!("blame"in a))throw new Error("Ref not found.");if(a.blame.ranges.length===0)throw new Error("File not found.");return{data:{ranges:a.blame.ranges.map(u=>{var l;return{startingLine:u.startingLine,endingLine:u.endingLine,commit:{oid:u.commit.oid,parentOids:((l=u.commit.parents.nodes)==null?void 0:l.map(p=>p.oid))||[],authoredDate:new Date(u.commit.authoredDate),author:u.commit.author?{name:u.commit.author.name,email:u.commit.author.email,avatarUrl:u.commit.author.avatarUrl}:null,committedDate:new Date(u.commit.committedDate),committer:u.commit.committer?{name:u.commit.committer.name,email:u.commit.committer.email,avatarUrl:u.commit.committer.avatarUrl}:null,message:u.commit.message,fileCount:u.commit.changedFilesIfAvailable,additions:u.commit.additions,deletions:u.commit.deletions}}})}}}async getFileContents(e,r={}){let n=await this.config.request({url:`${Oe(this.config,r)}/repos/${e.repo.namespace}/${e.repo.name}/contents/${encodeURIComponent(e.path)}?ref=${e.ref}`,headers:{...R(r.token||this.config.token),Accept:"application/vnd.github.raw+json"}});if(n.headers["content-type"].startsWith("application/json"))throw new Error(`GitHub: got directory when fetching "${e.path}", getFileContents does not support fetching directories`);if(!n.headers["content-type"].startsWith("application/vnd.github.raw+json"))throw new Error(`GitHub: unsupported content type "${n.headers["content-type"]}" when fetching "${e.path}"`);return{data:new Blob([n.body])}}async searchPullRequests(e,r={}){var d,c;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),a=O(o),i=n?n[0]>=3:!0,u=g=>{let m=g&&typeof e.isDraft=="boolean"?`${e.query} draft:${e.isDraft}`:e.query;return ke("pr",m,e.cursor,a,g,i)},l=await b(this.config,u(!0),r);l.body.errors&&ce(l.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(l=await b(this.config,u(!1),r));let{data:p}=l.body;if(!p)throw new Error(((d=l.body.errors)==null?void 0:d[0].message)||l.statusText||"Unknown error");return{pageInfo:{hasNextPage:p.search.pageInfo.hasNextPage,endCursor:p.search.pageInfo.endCursor},data:((c=p.search.nodes)==null?void 0:c.map(Qe))||[]}}async searchIssues(e,r={}){var u,l;let n=await this.getScopes(r),o=O(n),a=await b(this.config,ke("issue",e.query,e.cursor,o),r),{data:i}=a.body;if(!i)throw new Error(((u=a.body.errors)==null?void 0:u[0].message)||a.statusText||"Unknown error");return{pageInfo:{hasNextPage:i.search.pageInfo.hasNextPage,endCursor:i.search.pageInfo.endCursor},data:((l=i.search.nodes)==null?void 0:l.map(as))||[]}}async getPullRequestsAssociatedWithUser(e,r={}){return this.searchPullRequests({query:`involves:${e.username}`,cursor:e.cursor},r)}async getPullRequestsForRepos(e,r={}){let{assigneeLogins:n,updatedBefore:o,authorLogin:a,repos:i,reviewRequestedLogin:u,startQuery:l,mentionLogin:p}=e,d=xe(l||"");return i.forEach(c=>{d.push(`repo:${c.namespace}/${c.name}`)}),n&&n.forEach(c=>{d.push(`assignee:${c}`)}),o&&d.push(`updated:<${o}`),a&&d.push(`author:${a}`),u&&d.push(`review-requested:${u}`),p&&d.push(`mentions:${p}`),this.searchPullRequests({query:`sort:updated ${d.join(" ")}`,isDraft:e.isDraft,cursor:e.cursor},r)}async getPullRequestForRepo(e,r={}){var c,g;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),a=O(o),i=n?n[0]>=3:!0,u=m=>({query:`query getPullRequest(
|
|
406
|
+
$owner: String!
|
|
407
|
+
$name: String!
|
|
408
|
+
$number: Int!
|
|
409
|
+
) {
|
|
410
|
+
repository(
|
|
411
|
+
owner: $owner,
|
|
412
|
+
name: $name
|
|
413
|
+
) {
|
|
414
|
+
pullRequest(number: $number) {
|
|
415
|
+
${de(m,a,i)}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}`,variables:{owner:e.repo.namespace,name:e.repo.name,number:e.number}}),l=await b(this.config,u(!0),r);l.body.errors&&ce(l.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(l=await b(this.config,u(!1),r));let{data:p}=l.body;if(!p)throw new Error(((c=l.body.errors)==null?void 0:c[0].message)||l.statusText||"Unknown error");let d=(g=l.body.data)==null?void 0:g.repository.pullRequest;return{data:d?Qe(d):null}}async getPullRequestByGraphQLId(e,r={}){var c,g;let n=await this.getEnterpriseVersion(r),o=await this.getScopes(r),a=O(o),i=n?n[0]>=3:!0,u=m=>({query:`query getPullRequest(
|
|
419
|
+
$graphQLId: ID!
|
|
420
|
+
) {
|
|
421
|
+
node(id: $graphQLId) {
|
|
422
|
+
... on PullRequest {
|
|
423
|
+
${de(m,a,i)}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}`,variables:{graphQLId:e.graphQLId}}),l=await b(this.config,u(!0),r);l.body.errors&&ce(l.body.errors)&&(this.config.baseUrl||r.baseUrl)&&(l=await b(this.config,u(!1),r));let{data:p}=l.body;if(!p)throw new Error(((c=l.body.errors)==null?void 0:c[0].message)||l.statusText||"Unknown error");let d=(g=l.body.data)==null?void 0:g.node;return{data:d?Qe(d):null}}async closePullRequest(e,r={}){var i,u,l;let{pullRequestGraphQLId:n}=e,o=`mutation ClosePullRequest($pullRequestGraphQLId: ID!) {
|
|
406
427
|
closePullRequest(input: { pullRequestId: $pullRequestGraphQLId }) {
|
|
407
428
|
pullRequest {
|
|
408
429
|
id
|
|
@@ -510,7 +531,7 @@ query getBlame($owner: String!, $name: String!, $ref: String!, $path: String!) {
|
|
|
510
531
|
id
|
|
511
532
|
}
|
|
512
533
|
}
|
|
513
|
-
}`;if(!((p=(l=(u=(await b(this.config,{query:a,variables:{pullRequestGraphQLId:n,labelGraphQLIds:o}},r)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request labels")}async getIssuesForRepos(e,r={}){let n=
|
|
534
|
+
}`;if(!((p=(l=(u=(await b(this.config,{query:a,variables:{pullRequestGraphQLId:n,labelGraphQLIds:o}},r)).body.data)==null?void 0:u.updatePullRequest)==null?void 0:l.pullRequest)!=null&&p.id))throw new Error("Could not set pull request labels")}async getIssuesForRepos(e,r={}){let n=xe(e.startQuery||""),{cursor:o,assigneeLogins:a,updatedBefore:i,authorLogin:u,mentionLogin:l}=e;return e.repos.forEach(p=>{n.push(`repo:${p.namespace}/${p.name}`)}),a&&a.forEach(p=>{n.push(`assignee:${p}`)}),i&&n.push(`updated:<${i}`),u&&n.push(`author:${u}`),l&&n.push(`mentions:${l}`),this.searchIssues({query:`sort:updated ${n.join(" ")}`,cursor:o},r)}async closeIssueWithReason(e,r,n){var i,u,l;let o=`mutation CloseIssueWithReason($issueGraphQLId: ID!, $closeReason: IssueClosedStateReason!) {
|
|
514
535
|
closeIssue(input: { issueId: $issueGraphQLId, stateReason: $closeReason }) {
|
|
515
536
|
issue {
|
|
516
537
|
id
|
|
@@ -560,7 +581,7 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
|
|
|
560
581
|
}
|
|
561
582
|
}
|
|
562
583
|
}
|
|
563
|
-
`,variables:{owner:n,name:o,cursor:a,first:
|
|
584
|
+
`,variables:{owner:n,name:o,cursor:a,first:S}},r);if(!i.body.data)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:((l=i.body.data.repository.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=i.body.data.repository.milestones)==null?void 0:p.nodes)==null?void 0:d.map(je))??[]}}async getLabelsForRepo(e,r={}){var u,l,p,d;let{repo:{namespace:n,name:o},cursor:a}=e,i=await b(this.config,{query:`
|
|
564
585
|
query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first: Int!) {
|
|
565
586
|
repository(owner: $owner, name: $name) {
|
|
566
587
|
labels(first: $first, after: $cursor) {
|
|
@@ -574,7 +595,7 @@ query getLabelsForRepo($owner: String!, $name: String! $cursor: String, $first:
|
|
|
574
595
|
}
|
|
575
596
|
}
|
|
576
597
|
}
|
|
577
|
-
`,variables:{owner:n,name:o,cursor:a,first:
|
|
598
|
+
`,variables:{owner:n,name:o,cursor:a,first:S}},r);if(!i.body.data)throw new Error(((u=i.body.errors)==null?void 0:u[0].message)||i.statusText||"Unknown error");return{pageInfo:((l=i.body.data.repository.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((d=(p=i.body.data.repository.labels)==null?void 0:p.nodes)==null?void 0:d.map(Be))??[]}}};var os="https://gitlab.com/api/v4",is="https://gitlab.com/api/graphql",bt=/\/api\/v\d+$/,yt=t=>{if(t.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.")},Me=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),yt(e),e):os},us=(t,s)=>{let e=s.baseUrl||t.baseUrl;return e?(e=e.replace(/\/$/,""),yt(e),bt.test(e)&&(e=e.replace(bt,"")),`${e}/api/graphql`):is},y=(t,s,e)=>{let r=R(e.token||t.token);return t.request({url:us(t,e),method:"POST",headers:{...r,"Content-Type":"application/json"},body:JSON.stringify(s)})};var Xe=t=>t.split("/").slice(0,-1).join("/"),Ye=t=>t.split("/").at(-1)??"",V=t=>({id:t.id.replace(F,""),graphQLId:t.id,namespace:Xe(t.fullPath),name:Ye(t.fullPath),webUrl:t.webUrl}),Pt=t=>({id:t.id.replace(F,""),graphQLId:t.id,httpsUrl:t.httpUrlToRepo,namespace:Xe(t.fullPath),name:Ye(t.fullPath),sshUrl:t.sshUrlToRepo,webUrl:t.webUrl}),ls={assigned:"assignedMergeRequests",authored:"authoredMergeRequests",reviewRequested:"reviewRequestedMergeRequests"},ps={CAN_BE_MERGED:"MERGEABLE",CANNOT_BE_MERGED:"CONFLICTS",CANNOT_BE_MERGED_RECHECK:"UNKNOWN",UNCHECKED:"UNKNOWN",CHECKING:"UNKNOWN"},ds="gid://gitlab/User/",F="gid://gitlab/Project/",cs="gid://gitlab/MergeRequest/",gs="gid://gitlab/Issue/",ms="gid://gitlab/ProjectLabel/",wt="gid://gitlab/Milestone/",hs="gid://gitlab/Ci::Build/",Ze=`
|
|
578
599
|
description
|
|
579
600
|
dueDate
|
|
580
601
|
id
|
|
@@ -583,7 +604,7 @@ startDate
|
|
|
583
604
|
state
|
|
584
605
|
title
|
|
585
606
|
webPath
|
|
586
|
-
`,
|
|
607
|
+
`,ze=`
|
|
587
608
|
id
|
|
588
609
|
fullPath
|
|
589
610
|
webUrl
|
|
@@ -592,25 +613,25 @@ sshUrlToRepo
|
|
|
592
613
|
repository {
|
|
593
614
|
rootRef
|
|
594
615
|
}
|
|
595
|
-
`,
|
|
616
|
+
`,x=`
|
|
596
617
|
id
|
|
597
618
|
name
|
|
598
619
|
username
|
|
599
620
|
publicEmail
|
|
600
621
|
avatarUrl
|
|
601
622
|
webUrl
|
|
602
|
-
`,
|
|
623
|
+
`,et=`
|
|
603
624
|
color
|
|
604
625
|
description
|
|
605
626
|
id
|
|
606
627
|
title
|
|
607
|
-
`,
|
|
628
|
+
`,We=`
|
|
608
629
|
author {
|
|
609
|
-
${
|
|
630
|
+
${x}
|
|
610
631
|
}
|
|
611
632
|
assignees {
|
|
612
633
|
nodes {
|
|
613
|
-
${
|
|
634
|
+
${x}
|
|
614
635
|
}
|
|
615
636
|
}
|
|
616
637
|
closedAt
|
|
@@ -621,7 +642,7 @@ id
|
|
|
621
642
|
iid
|
|
622
643
|
labels {
|
|
623
644
|
nodes {
|
|
624
|
-
${
|
|
645
|
+
${et}
|
|
625
646
|
}
|
|
626
647
|
}
|
|
627
648
|
state
|
|
@@ -632,7 +653,7 @@ upvotes
|
|
|
632
653
|
userNotesCount
|
|
633
654
|
webUrl
|
|
634
655
|
milestone {
|
|
635
|
-
${
|
|
656
|
+
${Ze}
|
|
636
657
|
}
|
|
637
658
|
`,fs=`
|
|
638
659
|
stages {
|
|
@@ -650,12 +671,12 @@ stages {
|
|
|
650
671
|
name
|
|
651
672
|
}
|
|
652
673
|
}
|
|
653
|
-
`,
|
|
674
|
+
`,He=(t,s,e)=>`
|
|
654
675
|
id
|
|
655
676
|
state
|
|
656
677
|
approved
|
|
657
678
|
author {
|
|
658
|
-
${
|
|
679
|
+
${x}
|
|
659
680
|
}
|
|
660
681
|
diffRefs {
|
|
661
682
|
baseSha
|
|
@@ -680,12 +701,12 @@ targetBranch
|
|
|
680
701
|
sourceBranch
|
|
681
702
|
assignees {
|
|
682
703
|
nodes {
|
|
683
|
-
${
|
|
704
|
+
${x}
|
|
684
705
|
}
|
|
685
706
|
}
|
|
686
707
|
reviewers {
|
|
687
708
|
nodes {
|
|
688
|
-
${
|
|
709
|
+
${x}
|
|
689
710
|
mergeRequestInteraction {
|
|
690
711
|
approved
|
|
691
712
|
reviewState
|
|
@@ -695,19 +716,19 @@ reviewers {
|
|
|
695
716
|
mergeStatusEnum
|
|
696
717
|
labels {
|
|
697
718
|
nodes {
|
|
698
|
-
${
|
|
719
|
+
${et}
|
|
699
720
|
}
|
|
700
721
|
}
|
|
701
722
|
${t?"project { id httpUrlToRepo fullPath sshUrlToRepo webUrl } sourceProject { id httpUrlToRepo fullPath sshUrlToRepo webUrl }":""}
|
|
702
|
-
${s?`milestone { ${
|
|
723
|
+
${s?`milestone { ${Ze} }`:""}
|
|
703
724
|
${e?`headPipeline { ${fs} }`:""}
|
|
704
|
-
`,B=t=>`${t.namespace}/${t.name}`,Rs=t=>`${t.namespace}/${t.name}`,
|
|
725
|
+
`,B=t=>`${t.namespace}/${t.name}`,Rs=t=>`${t.namespace}/${t.name}`,Je=t=>{var s;return{id:t.id.replace(F,""),graphQLId:t.id,namespace:Xe(t.fullPath),name:Ye(t.fullPath),webUrl:t.webUrl,httpsUrl:t.httpUrlToRepo,sshUrl:t.sshUrlToRepo,defaultBranch:(s=t.repository)!=null&&s.rootRef?{name:t.repository.rootRef}:null,permission:null}},Is={opened:"OPEN",merged:"MERGED",closed:"CLOSED"},k=(t,s)=>{let e=t.avatarUrl;return!s&&(e!=null&&e.startsWith("/"))&&(e=`https://gitlab.com${e}`),{id:t.id.replace(ds,""),graphQLId:t.id,name:t.name,username:t.username,email:t.publicEmail??null,avatarUrl:e,url:t.webUrl}},tt=t=>({color:t.color,description:t.description,id:t.id.replace(ms,""),graphQLId:t.id,name:t.title}),bs=(t,s)=>t?t==="FAILED"&&s?"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"}[t]:null,Ke=(t,s,e,r)=>{var o,a,i,u,l,p,d,c,g,m,f,I;let n=(o=t.reviewers)!=null&&o.nodes?t.reviewers.nodes.map(h=>{var P,D;return{reviewer:k(h,r),state:(P=h.mergeRequestInteraction)!=null&&P.approved?"APPROVED":((D=h.mergeRequestInteraction)==null?void 0:D.reviewState)==="REVIEWED"?"CHANGES_REQUESTED":"CHANGES_REQUESTED"}}):null;return{id:t.id.replace(cs,""),graphQLId:t.id,title:t.title,number:parseInt(t.iid,10),state:Is[t.state],commentCount:t.userNotesCount||0,upvoteCount:t.upvotes,author:t.author?k(t.author,r):null,createdDate:new Date(t.createdAt),isDraft:t.draft,repository:{id:s.id,graphQLId:s.graphQLId,name:s.name,owner:{login:s.namespace},remoteInfo:s.httpsUrl&&s.sshUrl?{cloneUrlHTTPS:s.httpsUrl,cloneUrlSSH:s.sshUrl}:null},headRepository:e?{id:e.id,graphQLId:e.graphQLId,name:e.name,owner:{login:e.namespace},remoteInfo:{cloneUrlHTTPS:e.httpsUrl,cloneUrlSSH:e.sshUrl}}:null,headCommit:{buildStatuses:((u=(i=(a=t.headPipeline)==null?void 0:a.stages)==null?void 0:i.nodes)==null?void 0:u.flatMap(h=>{var P,D;return((D=(P=h.jobs)==null?void 0:P.nodes)==null?void 0:D.map(E=>({completedAt:E.finishedAt?new Date(E.finishedAt):null,description:null,name:E.name??null,state:bs(E.status,E.allowFailure),stage:h.name??null,startedAt:new Date(E.createdAt),url:`${s.webUrl}/-/jobs/${E.id.replace(hs,"")}`})))??[]}))??[]},baseRef:{name:t.targetBranch,oid:((l=t.diffRefs)==null?void 0:l.baseSha)??null},headRef:{name:t.sourceBranch,oid:((p=t.diffRefs)==null?void 0:p.headSha)??null},url:t.webUrl,updatedDate:new Date(t.updatedAt),closedDate:t.mergedAt?new Date(t.mergedAt):null,mergedDate:t.mergedAt?new Date(t.mergedAt):null,assignees:(d=t.assignees)!=null&&d.nodes?t.assignees.nodes.map(h=>k(h,r)):null,reviews:n,reviewDecision:t.approved?"APPROVED":Q(n),additions:((c=t.diffStatsSummary)==null?void 0:c.additions)||0,deletions:((g=t.diffStatsSummary)==null?void 0:g.deletions)||0,fileCount:((m=t.diffStatsSummary)==null?void 0:m.fileCount)||0,commitCount:t.commitCount||0,mergeableState:ps[t.mergeStatusEnum],milestone:t.milestone?st(t.milestone,s.webUrl):null,labels:((I=(f=t.labels)==null?void 0:f.nodes)==null?void 0:I.map(tt))??[],permissions:null}},Ve=(t,s,e)=>{var r,n;return{author:k(t.author,e),assignees:t.assignees.nodes.map(o=>k(o,e)),commentCount:t.userNotesCount,closedDate:t.closedAt?new Date(t.closedAt):null,createdDate:new Date(t.createdAt),description:t.description,graphQLId:t.id,id:t.id.replace(gs,""),labels:((n=(r=t.labels)==null?void 0:r.nodes)==null?void 0:n.map(tt))??[],number:t.iid,repository:{id:s.id.replace(F,""),graphQLId:s.id,name:s.name,owner:{login:s.namespace}},updatedDate:new Date(t.updatedAt),upvoteCount:t.upvotes,state:{name:t.state,color:null},type:t.type,title:t.title,url:t.webUrl,milestone:t.milestone?st(t.milestone,s.webUrl):null}},st=(t,s)=>({id:t.id.replace(wt,""),graphQLId:t.id,number:parseInt(t.iid,10),title:t.title,description:t.description,isOpen:t.state==="active",url:`${s}/-/${t.webPath.replace(/.+?\/-\//,"")}`,startDate:t.startDate?new Date(t.startDate):null,dueDate:t.dueDate?new Date(t.dueDate):null}),X=class extends L{getIsSelfHosted(s){return!!s.baseUrl||!!this.config.baseUrl}async getCurrentUser(s={},e={}){var o;let n=(o=(await y(this.config,{query:`
|
|
705
726
|
query getCurrentUser {
|
|
706
727
|
currentUser {
|
|
707
|
-
${
|
|
728
|
+
${x}
|
|
708
729
|
}
|
|
709
730
|
}
|
|
710
|
-
`},e)).body.data)==null?void 0:o.currentUser;if(!n)throw new Error("Current user not found.");return{data:
|
|
731
|
+
`},e)).body.data)==null?void 0:o.currentUser;if(!n)throw new Error("Current user not found.");return{data:k(n,this.getIsSelfHosted(e))}}async getUserForCommit(s,e={}){var a,i,u,l;let r=B(s.repo),o=(l=(u=(i=(a=(await y(this.config,{query:`
|
|
711
732
|
query getUserForCommit($fullPath: ID!, $oid: String!) {
|
|
712
733
|
project(fullPath: $fullPath) {
|
|
713
734
|
repository {
|
|
@@ -725,17 +746,17 @@ query getUserForCommit($fullPath: ID!, $oid: String!) {
|
|
|
725
746
|
query getAccountForEmail($email: String!) {
|
|
726
747
|
users(search: $email) {
|
|
727
748
|
nodes {
|
|
728
|
-
${
|
|
749
|
+
${x}
|
|
729
750
|
}
|
|
730
751
|
}
|
|
731
752
|
}
|
|
732
|
-
`,variables:{email:s.email}},e)).body.data)==null?void 0:o.users)==null?void 0:a.nodes)==null?void 0:i[0];if(!n)throw new Error("User not found.");return{data:
|
|
753
|
+
`,variables:{email:s.email}},e)).body.data)==null?void 0:o.users)==null?void 0:a.nodes)==null?void 0:i[0];if(!n)throw new Error("User not found.");return{data:k(n,this.getIsSelfHosted(e))}}async getAccountForUsername(s,e={}){var o;let n=(o=(await y(this.config,{query:`
|
|
733
754
|
query getAccountForUsername($username: String!) {
|
|
734
755
|
user(username: $username) {
|
|
735
|
-
${
|
|
756
|
+
${x}
|
|
736
757
|
}
|
|
737
758
|
}
|
|
738
|
-
`,variables:{username:s.username}},e)).body.data)==null?void 0:o.user;if(!n)throw new Error("User not found.");return{data:
|
|
759
|
+
`,variables:{username:s.username}},e)).body.data)==null?void 0:o.user;if(!n)throw new Error("User not found.");return{data:k(n,this.getIsSelfHosted(e))}}async getAccountsForRepo(s,e={}){var u,l,p,d,c,g,m;let{repo:{namespace:r,name:n},cursor:o}=s,a=await y(this.config,{query:`
|
|
739
760
|
query getAccountsForRepo(
|
|
740
761
|
$fullPath: ID!
|
|
741
762
|
$after: String
|
|
@@ -746,7 +767,7 @@ query getAccountsForRepo(
|
|
|
746
767
|
projectMembers(after: $after) {
|
|
747
768
|
nodes {
|
|
748
769
|
user {
|
|
749
|
-
${
|
|
770
|
+
${x}
|
|
750
771
|
}
|
|
751
772
|
}
|
|
752
773
|
pageInfo {
|
|
@@ -756,22 +777,22 @@ query getAccountsForRepo(
|
|
|
756
777
|
}
|
|
757
778
|
}
|
|
758
779
|
}
|
|
759
|
-
`,variables:{fullPath:`${r}/${n}`,after:o}},e),i=(d=(p=(l=(u=a.body.data)==null?void 0:u.project)==null?void 0:l.projectMembers)==null?void 0:p.nodes)==null?void 0:d.map(f=>f.user).filter(f=>f!==null);return{pageInfo:((m=(g=(c=a.body.data)==null?void 0:c.project)==null?void 0:g.projectMembers)==null?void 0:m.pageInfo)??{endCursor:null,hasNextPage:!1},data:(i==null?void 0:i.map(f=>
|
|
780
|
+
`,variables:{fullPath:`${r}/${n}`,after:o}},e),i=(d=(p=(l=(u=a.body.data)==null?void 0:u.project)==null?void 0:l.projectMembers)==null?void 0:p.nodes)==null?void 0:d.map(f=>f.user).filter(f=>f!==null);return{pageInfo:((m=(g=(c=a.body.data)==null?void 0:c.project)==null?void 0:g.projectMembers)==null?void 0:m.pageInfo)??{endCursor:null,hasNextPage:!1},data:(i==null?void 0:i.map(f=>k(f,this.getIsSelfHosted(e))))??[]}}async getRepo(s,e={}){var o;let r=B(s),n=await y(this.config,{query:`
|
|
760
781
|
query getRepo($fullPath: ID!) {
|
|
761
782
|
project(fullPath: $fullPath) {
|
|
762
|
-
${
|
|
783
|
+
${ze}
|
|
763
784
|
}
|
|
764
785
|
}
|
|
765
|
-
`,variables:{fullPath:r}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);return{data:
|
|
786
|
+
`,variables:{fullPath:r}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);return{data:Je(n.body.data.project)}}async getRepos(s,e={}){let n=s.map(B).map((u,l)=>`
|
|
766
787
|
getRepo_${l}: project(fullPath: "${u}") {
|
|
767
|
-
${
|
|
788
|
+
${ze}
|
|
768
789
|
}
|
|
769
790
|
`).join(`
|
|
770
791
|
`),o=await y(this.config,{query:`
|
|
771
792
|
query batchGetRepos {
|
|
772
793
|
${n}
|
|
773
794
|
}
|
|
774
|
-
`},e);if(!o.body.data)throw new Error(o.statusText||"Unknown error");let a=[],i=[];return s.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(
|
|
795
|
+
`},e);if(!o.body.data)throw new Error(o.statusText||"Unknown error");let a=[],i=[];return s.forEach((u,l)=>{let p=o.body.data[`getRepo_${l}`];p?a.push(Je(p)):i.push({input:u})}),{data:a,errors:i}}async getReposForCurrentUser(s={},e={}){var o,a,i,u,l,p;let r=await y(this.config,{query:`
|
|
775
796
|
query getReposForCurrentUser($after: String) {
|
|
776
797
|
projects(membership: true first: 100 after: $after) {
|
|
777
798
|
pageInfo {
|
|
@@ -779,11 +800,11 @@ query getReposForCurrentUser($after: String) {
|
|
|
779
800
|
hasNextPage
|
|
780
801
|
}
|
|
781
802
|
nodes {
|
|
782
|
-
${
|
|
803
|
+
${ze}
|
|
783
804
|
}
|
|
784
805
|
}
|
|
785
806
|
}
|
|
786
|
-
`,variables:{after:s.cursor}},e);if(!((o=r.body.data)!=null&&o.projects))throw new Error(((a=r.body.errors)==null?void 0:a[0].message)||r.statusText||"Unknown error");let n=((u=(i=r.body.data)==null?void 0:i.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(
|
|
807
|
+
`,variables:{after:s.cursor}},e);if(!((o=r.body.data)!=null&&o.projects))throw new Error(((a=r.body.errors)==null?void 0:a[0].message)||r.statusText||"Unknown error");let n=((u=(i=r.body.data)==null?void 0:i.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(Je)}}async getRefs(s,e,r={}){var u;let n=B(e.repo),o=new URL(`${Me(this.config,r)}/projects/${encodeURIComponent(n)}/repository/${s}`);o.searchParams.set("page",((u=e.page)==null?void 0:u.toString())||"1"),o.searchParams.set("per_page",S.toString());let a=await this.config.request({url:o.toString(),headers:R(r.token||this.config.token)}),i=a.headers["x-next-page"];return{pageInfo:{hasNextPage:!!i,nextPage:i?parseInt(i,10):null},data:a.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(s,e={}){return this.getRefs("branches",s,e)}async getTags(s,e={}){return this.getRefs("tags",s,e)}async getBlame(s,e={}){let r=B(s.repo),n=new URL(`${Me(this.config,e)}/projects/${encodeURIComponent(r)}/repository/files/${encodeURIComponent(s.path)}/blame`);n.searchParams.set("ref",s.ref);let o=await this.config.request({url:n.toString(),headers:R(e.token||this.config.token)}),a=0;return{data:{ranges:o.body.map(i=>{let u=a+1;return a+=i.lines.length,{startingLine:u,endingLine:a,commit:{oid:i.commit.id,parentOids:i.commit.parent_ids,authoredDate:new Date(i.commit.authored_date),author:{name:i.commit.author_name,email:i.commit.author_email,avatarUrl:null},committedDate:new Date(i.commit.committed_date),committer:{name:i.commit.committer_name,email:i.commit.committer_email,avatarUrl:null},message:i.commit.message,fileCount:null,additions:null,deletions:null}}})}}}async getPullRequestsForUser(s,e={}){var a,i;let r=ls[s.association],n=await y(this.config,{query:`
|
|
787
808
|
query getPullRequestsForUser($username: String! $cursor: String) {
|
|
788
809
|
user(username: $username) {
|
|
789
810
|
${r}(state:opened first:100 after:$cursor) {
|
|
@@ -792,12 +813,12 @@ query getPullRequestsForUser($username: String! $cursor: String) {
|
|
|
792
813
|
hasNextPage
|
|
793
814
|
}
|
|
794
815
|
nodes {
|
|
795
|
-
${
|
|
816
|
+
${He(!0,!0,!0)}
|
|
796
817
|
}
|
|
797
818
|
}
|
|
798
819
|
}
|
|
799
820
|
}
|
|
800
|
-
`,variables:{username:s.username,cursor:s.cursor}},e);if(!n.body.data)throw new Error(((a=n.body.errors)==null?void 0:a[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:((i=o.nodes)==null?void 0:i.map(u=>
|
|
821
|
+
`,variables:{username:s.username,cursor:s.cursor}},e);if(!n.body.data)throw new Error(((a=n.body.errors)==null?void 0:a[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:((i=o.nodes)==null?void 0:i.map(u=>Ke(u,Pt(u.project),Pt(u.sourceProject),this.getIsSelfHosted(e))))||[]}}async getPullRequestsAssociatedWithUser(s,e={}){var c;let[r,n,o]=((c=s.cursor)==null?void 0:c.split(";"))||[void 0,void 0,void 0],[a,i,u]=await Promise.all([r==="null"?null:this.getPullRequestsForUser({username:s.username,association:"authored",cursor:r},e),n==="null"?null:this.getPullRequestsForUser({username:s.username,association:"assigned",cursor:n},e),o==="null"?null:this.getPullRequestsForUser({username:s.username,association:"reviewRequested",cursor:o},e)]),l={},p=[],d=g=>{l[g.id]||(l[g.id]=!0,p.push(g))};return a==null||a.data.forEach(d),i==null||i.data.forEach(d),u==null||u.data.forEach(d),{pageInfo:{hasNextPage:(a==null?void 0:a.pageInfo.hasNextPage)||(i==null?void 0:i.pageInfo.hasNextPage)||(u==null?void 0:u.pageInfo.hasNextPage)||!1,endCursor:`${(a==null?void 0:a.pageInfo.hasNextPage)&&(a==null?void 0:a.pageInfo.endCursor)||"null"};${(i==null?void 0:i.pageInfo.hasNextPage)&&(i==null?void 0:i.pageInfo.endCursor)||"null"};${(u==null?void 0:u.pageInfo.hasNextPage)&&(u==null?void 0:u.pageInfo.endCursor)||"null"}`},data:p}}getVariablesForPullRequests(s){let{updatedBefore:e,isDraft:r,authorLogin:n,assigneeLogins:o,reviewRequestedLogin:a}=s||{},i={},u=[],l=[],p=(d,c,g)=>{u.push(`$${d}: ${g}`),l.push(`${d}: $${d}`),i[d]=c};return e&&p("updatedBefore",e,"Time"),n&&p("authorUsername",n,"String"),o&&p("assigneeUsername",o[0],"String"),r!=null&&p("draft",r,"Boolean"),a&&p("reviewerUsername",a,"String"),{variables:i,variableTypes:u,mergeRequestArguments:l}}async getPullRequestsForRepo(s,e={}){var f,I,h;let{cursor:r,repo:n}=s||{},o=B(n),{variables:a,variableTypes:i,mergeRequestArguments:u}=this.getVariablesForPullRequests(s),l={fullPath:o,...a},p=await y(this.config,{query:`
|
|
801
822
|
query getPullRequestsForRepo(
|
|
802
823
|
$fullPath: ID!
|
|
803
824
|
$after: String
|
|
@@ -821,12 +842,12 @@ query getPullRequestsForRepo(
|
|
|
821
842
|
hasNextPage
|
|
822
843
|
}
|
|
823
844
|
nodes {
|
|
824
|
-
${
|
|
845
|
+
${He(!1,!0,!0)}
|
|
825
846
|
}
|
|
826
847
|
}
|
|
827
848
|
}
|
|
828
849
|
}
|
|
829
|
-
`,variables:{...l,after:r}},e),d=[],c=(f=p.body.data)==null?void 0:f.project,g=V(c||{id:"",fullPath:"",webUrl:""});return(((I=c==null?void 0:c.mergeRequests)==null?void 0:I.nodes)||[]).forEach(P=>{d.push(
|
|
850
|
+
`,variables:{...l,after:r}},e),d=[],c=(f=p.body.data)==null?void 0:f.project,g=V(c||{id:"",fullPath:"",webUrl:""});return(((I=c==null?void 0:c.mergeRequests)==null?void 0:I.nodes)||[]).forEach(P=>{d.push(Ke(P,g,null,this.getIsSelfHosted(e)))}),{pageInfo:(h=c==null?void 0:c.mergeRequests)==null?void 0:h.pageInfo,data:d}}async getPullRequestsForRepos(s,e={}){var c,g,m,f,I;let{cursor:r}=s||{},n=s.repoIds.map(h=>h.toString().startsWith(F)?h:`${F}${h}`),{variables:o,variableTypes:a,mergeRequestArguments:i}=this.getVariablesForPullRequests(s),u={projectIds:n,...o},l=await y(this.config,{query:`
|
|
830
851
|
query getPullRequests(
|
|
831
852
|
$projectIds: [ID!]
|
|
832
853
|
$after: String
|
|
@@ -851,13 +872,13 @@ query getPullRequests(
|
|
|
851
872
|
${i.length?i.join(" "):""}
|
|
852
873
|
) {
|
|
853
874
|
nodes {
|
|
854
|
-
${
|
|
875
|
+
${He(!1,!1,!1)}
|
|
855
876
|
}
|
|
856
877
|
}
|
|
857
878
|
}
|
|
858
879
|
}
|
|
859
880
|
}
|
|
860
|
-
`,variables:{...u,after:r}},e),p=[];return(((g=(c=l.body.data)==null?void 0:c.projects)==null?void 0:g.nodes)||[]).forEach(h=>{var
|
|
881
|
+
`,variables:{...u,after:r}},e),p=[];return(((g=(c=l.body.data)==null?void 0:c.projects)==null?void 0:g.nodes)||[]).forEach(h=>{var E;let P=V(h);(((E=h.mergeRequests)==null?void 0:E.nodes)||[]).forEach(se=>{p.push(Ke(se,P,null,this.getIsSelfHosted(e)))})}),{pageInfo:(I=(f=(m=l.body)==null?void 0:m.data)==null?void 0:f.projects)==null?void 0:I.pageInfo,data:p}}async closePullRequest(s,e={}){var l,p,d;let{repo:{namespace:r,name:n},pullRequestId:o}=s,a=`mutation ClosePullRequest($fullPath: ID!, $pullRequestId: String!) {
|
|
861
882
|
mergeRequestUpdate(input: { projectPath: $fullPath, iid: $pullRequestId, state: CLOSED }) {
|
|
862
883
|
errors,
|
|
863
884
|
mergeRequest {
|
|
@@ -922,11 +943,11 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
922
943
|
fullPath
|
|
923
944
|
webUrl
|
|
924
945
|
issue(iid: $issueId) {
|
|
925
|
-
${
|
|
946
|
+
${We}
|
|
926
947
|
}
|
|
927
948
|
}
|
|
928
949
|
}
|
|
929
|
-
`,variables:{issueId:s.id,projectId:r}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);if(!((i=(a=n.body.data)==null?void 0:a.project)!=null&&i.issue))throw new Error(`Issue ${s.id} not found`);return{data:
|
|
950
|
+
`,variables:{issueId:s.id,projectId:r}},e);if(!((o=n.body.data)!=null&&o.project))throw new Error(`Repository ${r} not found`);if(!((i=(a=n.body.data)==null?void 0:a.project)!=null&&i.issue))throw new Error(`Issue ${s.id} not found`);return{data:Ve(n.body.data.project.issue,V(n.body.data.project),this.getIsSelfHosted(e))}}getVariablesForIssues(s){let{updatedBefore:e,authorLogin:r,assigneeLogins:n}=s||{},o={},a=[],i=[],u=(l,p,d)=>{a.push(`$${l}: ${d}`),i.push(`${l}: $${l}`),o[l]=p};return e&&u("updatedBefore",e,"Time"),r&&u("authorUsername",r,"String"),n&&u("assigneeUsername",n[0],"String"),{variables:o,variableTypes:a,issueArguments:i}}async getIssuesForRepo(s,e={}){var I,h,P;let{cursor:r,repo:n}=s||{},o=B(n),{variables:a,variableTypes:i,issueArguments:u}=this.getVariablesForIssues(s),l={fullPath:o,...a},p=`
|
|
930
951
|
query GetIssuesFromProject(
|
|
931
952
|
$fullPath: ID!
|
|
932
953
|
$after: String
|
|
@@ -946,7 +967,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
946
967
|
${u.length?u.join(" "):""}
|
|
947
968
|
) {
|
|
948
969
|
nodes {
|
|
949
|
-
${
|
|
970
|
+
${We}
|
|
950
971
|
}
|
|
951
972
|
pageInfo {
|
|
952
973
|
endCursor
|
|
@@ -954,7 +975,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
954
975
|
}
|
|
955
976
|
}
|
|
956
977
|
}
|
|
957
|
-
}`,d=await y(this.config,{query:p,variables:{...l,after:r}},e),c=[],g=(I=d.body.data)==null?void 0:I.project,m=V(g||{id:"",fullPath:"",webUrl:""});return(((h=g==null?void 0:g.issues)==null?void 0:h.nodes)||[]).forEach(D=>{c.push(
|
|
978
|
+
}`,d=await y(this.config,{query:p,variables:{...l,after:r}},e),c=[],g=(I=d.body.data)==null?void 0:I.project,m=V(g||{id:"",fullPath:"",webUrl:""});return(((h=g==null?void 0:g.issues)==null?void 0:h.nodes)||[]).forEach(D=>{c.push(Ve(D,m,this.getIsSelfHosted(e)))}),{pageInfo:(P=g==null?void 0:g.issues)==null?void 0:P.pageInfo,data:c.sort((D,E)=>(D.updatedDate||D.createdDate).getTime()-(E.updatedDate||E.createdDate).getTime())}}async getIssuesForRepos(s,e={}){var g,m,f,I,h;let{cursor:r}=s||{},n=s.repoIds.map(P=>P.toString().startsWith(F)?P:`${F}${P}`),{variables:o,variableTypes:a,mergeRequestArguments:i}=this.getVariablesForPullRequests(s),u={projectIds:n,...o},l=`
|
|
958
979
|
query GetIssuesFromProject(
|
|
959
980
|
$projectIds: [ID!]
|
|
960
981
|
$after: String
|
|
@@ -979,12 +1000,12 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
979
1000
|
${i.length?i.join(" "):""}
|
|
980
1001
|
) {
|
|
981
1002
|
nodes {
|
|
982
|
-
${
|
|
1003
|
+
${We}
|
|
983
1004
|
}
|
|
984
1005
|
}
|
|
985
1006
|
}
|
|
986
1007
|
}
|
|
987
|
-
}`,p=await y(this.config,{query:l,variables:{...u,after:r}},e),d=[];return(((m=(g=p.body.data)==null?void 0:g.projects)==null?void 0:m.nodes)||[]).forEach(P=>{var se;let D=V(P);(((se=P.issues)==null?void 0:se.nodes)||[]).forEach(
|
|
1008
|
+
}`,p=await y(this.config,{query:l,variables:{...u,after:r}},e),d=[];return(((m=(g=p.body.data)==null?void 0:g.projects)==null?void 0:m.nodes)||[]).forEach(P=>{var se;let D=V(P);(((se=P.issues)==null?void 0:se.nodes)||[]).forEach(Dt=>d.push(Ve(Dt,D,this.getIsSelfHosted(e))))}),{pageInfo:(h=(I=(f=p.body)==null?void 0:f.data)==null?void 0:I.projects)==null?void 0:h.pageInfo,data:d.sort((P,D)=>(P.updatedDate||P.createdDate).getTime()-(D.updatedDate||D.createdDate).getTime())}}async setIssueStatus(s,e={}){var l,p,d;let{repo:{namespace:r,name:n},issueId:o,status:a}=s,i=`mutation SetIssueState($fullPath: ID!, $issueId: String!, $status: IssueStateEvent!) {
|
|
988
1009
|
updateIssue(input: { projectPath: $fullPath, iid: $issueId, stateEvent: $status }) {
|
|
989
1010
|
issue {
|
|
990
1011
|
id
|
|
@@ -996,7 +1017,7 @@ query GetSingleIssue($projectId: ID!, $issueId: String!) {
|
|
|
996
1017
|
id
|
|
997
1018
|
}
|
|
998
1019
|
}
|
|
999
|
-
}`;if(!((d=(p=(l=(await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,issueId:o,labelGraphQLIds:a}},e)).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(s,e={}){var p,d,c,g;let{repo:{namespace:r,name:n},issueId:o}=s,a=((p=s.milestoneGraphQLId)==null?void 0:p.replace(
|
|
1020
|
+
}`;if(!((d=(p=(l=(await y(this.config,{query:i,variables:{fullPath:`${r}/${n}`,issueId:o,labelGraphQLIds:a}},e)).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(s,e={}){var p,d,c,g;let{repo:{namespace:r,name:n},issueId:o}=s,a=((p=s.milestoneGraphQLId)==null?void 0:p.replace(wt,""))??"",i=`mutation SetIssueMilestone($fullPath: ID!, $issueId: String!, $milestoneGraphQLId: ID) {
|
|
1000
1021
|
updateIssue(input: { projectPath: $fullPath, iid: $issueId, milestoneId: $milestoneGraphQLId }) {
|
|
1001
1022
|
errors
|
|
1002
1023
|
issue {
|
|
@@ -1024,7 +1045,7 @@ query getLabelsForRepo(
|
|
|
1024
1045
|
webUrl
|
|
1025
1046
|
milestones(after: $after) {
|
|
1026
1047
|
nodes {
|
|
1027
|
-
${
|
|
1048
|
+
${Ze}
|
|
1028
1049
|
}
|
|
1029
1050
|
pageInfo {
|
|
1030
1051
|
endCursor
|
|
@@ -1033,7 +1054,7 @@ query getLabelsForRepo(
|
|
|
1033
1054
|
}
|
|
1034
1055
|
}
|
|
1035
1056
|
}
|
|
1036
|
-
`,variables:{fullPath:`${r}/${n}`,after:o}},e);return{pageInfo:((l=(u=(i=a.body.data)==null?void 0:i.project)==null?void 0:u.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=a.body.data)==null?void 0:p.project)==null?void 0:d.milestones)==null?void 0:c.nodes)==null?void 0:g.map(m=>{var f,I;return
|
|
1057
|
+
`,variables:{fullPath:`${r}/${n}`,after:o}},e);return{pageInfo:((l=(u=(i=a.body.data)==null?void 0:i.project)==null?void 0:u.milestones)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=a.body.data)==null?void 0:p.project)==null?void 0:d.milestones)==null?void 0:c.nodes)==null?void 0:g.map(m=>{var f,I;return st(m,((I=(f=a.body.data)==null?void 0:f.project)==null?void 0:I.webUrl)||"")}))??[]}}async getLabelsForRepo(s,e={}){var i,u,l,p,d,c,g;let{repo:{namespace:r,name:n},cursor:o}=s,a=await y(this.config,{query:`
|
|
1037
1058
|
query getLabelsForRepo(
|
|
1038
1059
|
$fullPath: ID!
|
|
1039
1060
|
$after: String
|
|
@@ -1043,7 +1064,7 @@ query getLabelsForRepo(
|
|
|
1043
1064
|
) {
|
|
1044
1065
|
labels(after: $after) {
|
|
1045
1066
|
nodes {
|
|
1046
|
-
${
|
|
1067
|
+
${et}
|
|
1047
1068
|
}
|
|
1048
1069
|
pageInfo {
|
|
1049
1070
|
endCursor
|
|
@@ -1052,5 +1073,5 @@ query getLabelsForRepo(
|
|
|
1052
1073
|
}
|
|
1053
1074
|
}
|
|
1054
1075
|
}
|
|
1055
|
-
`,variables:{fullPath:`${r}/${n}`,after:o}},e);return{pageInfo:((l=(u=(i=a.body.data)==null?void 0:i.project)==null?void 0:u.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=a.body.data)==null?void 0:p.project)==null?void 0:d.labels)==null?void 0:c.nodes)==null?void 0:g.map(
|
|
1056
|
-
OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUser())`,l=(await t.request({url:`${z(t,r,o)}/rest/api/2/search?jql=${i}&startAt=${a}&maxResults=${de}&fields=${["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components"].join(",")}&expand=transitions`,headers:R(r.token||t.token)})).body.issues.map(d=>Pt(d,e,!o)),p=l.length==de;return{data:l,pageInfo:{hasNextPage:p,nextPage:p?a+l.length:null}}},me=async(t,s,e,r={})=>{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 t.request({url:`${z(t,r,l)}/rest/api/2/search?jql=${d.join(" AND ")}&startAt=${p}&maxResults=${de}&fields=${["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components"].join(",")}&expand=transitions`,headers:R(r.token||t.token)})).body.issues.map(f=>Pt(f,e,!l)),m=g.length==de;return{data:g,pageInfo:{hasNextPage:m,nextPage:m?p+g.length:null}}},he=async(t,s,e={})=>{let{resourceId:r,issueId:n,labelNames:o}=s,a={fields:{labels:o}};await t.request({method:"PUT",url:`${z(t,e,r)}/rest/api/2/issue/${n}`,body:JSON.stringify(a),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},fe=async(t,s,e={})=>{let{resourceId:r,issueId:n,componentIds:o}=s,a={fields:{components:o.map(i=>({id:i}))}};await t.request({method:"PUT",url:`${z(t,e,r)}/rest/api/2/issue/${n}`,body:JSON.stringify(a),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},Re=async(t,s,e={})=>{let{resourceId:r,issueId:n,status:o}=s,a={transition:{id:o}};await t.request({method:"POST",url:`${z(t,e,r)}/rest/api/2/issue/${n}/transitions`,body:JSON.stringify(a),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},Ie=async(t,s,e={})=>{let{resourceId:r,projectIdOrKey:n}=s,o=new URL(`${z(t,e,r)}/rest/api/2/project/${n}/components`);return{data:(await t.request({url:o.toString(),headers:R(e.token||t.token)})).body}};var Y="https://api.atlassian.com/ex/jira",Ze=100,Z=class extends v{constructor(){super(...arguments);this._resourceUrlCache={}}async getResourceUrl(e,r={}){var a;let n=r.token||this.config.token;if(!n)return null;let o=this._resourceUrlCache[n];return o?o[e.resourceId]??null:(await this.getJiraResourcesForCurrentUser(r),((a=this._resourceUrlCache[n])==null?void 0:a[e.resourceId])??null)}async getCurrentUserForResource(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r),o=await this.config.request({url:`${r.baseUrl||Y}/${e.resourceId}/rest/api/2/myself`,headers:R(r.token||this.config.token)});return{data:{name:o.body.displayName,email:o.body.emailAddress,avatarUrl:o.body.avatarUrls["48x48"],id:o.body.accountId,username:o.body.displayName,url:n?`${n}/jira/people/${o.body.accountId}`:null}}}async getJiraResourcesForCurrentUser(e={}){let r=await this.config.request({url:`${e.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:R(e.token||this.config.token)}),n=e.token||this.config.token,o=n?this._resourceUrlCache[n]||{}:void 0,a=r.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,r={}){let n=new URL(`${r.baseUrl||Y}/${e.resourceId}/rest/api/2/project/search`);n.searchParams.set("maxResults",Ze.toString()),e.cursor&&n.searchParams.set("startAt",e.cursor);let o=await this.config.request({url:n.toString(),headers:R(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(a=>({id:a.id,key:a.key,name:a.name,resourceId:e.resourceId}))}}async getJiraProjectsForResources(e,r={}){let n=[];return await Promise.all(e.resourceIds.map(async o=>{let a=await this.getJiraProjectsForResource({resourceId:o},r);n.push(...a.data)})),{data:n}}async getAccountsForJiraProject(e,r={}){let{resourceId:n,projectKey:o,cursor:a}=e,i=await this.getResourceUrl({resourceId:n},r),u=new URL(`${r.baseUrl||Y}/${n}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",Ze.toString()),a&&u.searchParams.set("startAt",a),u.searchParams.set("project",o);let l=await this.config.request({url:u.toString(),headers:R(r.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=>ce(p,i,!1))}}async getComponentsForJiraProject(e,r={}){return await Ie(this.config,e,r)}async getIssuesForProject(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r);return await me(this.config,e,n,r)}async getIssuesForResourceForCurrentUser(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r);return await ge(this.config,e,n,r)}async setIssueStatus(e,r={}){await Re(this.config,e,r)}async setIssueAssignee(e,r={}){let{resourceId:n,issueId:o,assigneeId:a}=e,i={accountId:a};await this.config.request({method:"PUT",url:`${r.baseUrl||Y}/${n}/rest/api/2/issue/${o}/assignee`,body:JSON.stringify(i),headers:{...R(r.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(e,r={}){await fe(this.config,e,r)}async setIssueLabels(e,r={}){await he(this.config,e,r)}async getLabelsForResource(e,r={}){let{resourceId:n,cursor:o}=e,a=new URL(`${r.baseUrl||Y}/${n}/rest/api/2/label`);a.searchParams.set("maxResults",Ze.toString()),o&&a.searchParams.set("startAt",o);let i=await this.config.request({url:a.toString(),headers:R(r.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 ee=class extends L{async getCurrentUser(s={}){let e=await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/myself`,headers:R((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:R((s==null?void 0:s.token)||this.config.token)})).body.map(r=>({id:r.id,name:r.name}))}}async getIssuesForProject(s,e={}){if(!e.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await me(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 ge(this.config,s,e.baseUrl,e)}async setIssueStatus(s,e={}){await Re(this.config,s,e)}async setIssueLabels(s,e={}){await he(this.config,s,e)}async setIssueComponents(s,e={}){await fe(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:R(s.token||this.config.token)})).body.results.map(({displayName:r})=>({color:null,description:null,id:null,name:r}))}}async getComponentsForJiraProject(s,e={}){return await Ie(this.config,s,e)}};var k="https://api.trello.com",Es=1e3,Cs=(t,s)=>{let e=new Date(1e3*parseInt(t.id.substring(0,8),16));return{id:t.id,commentCount:t.badges.comments,number:t.idShort.toString(),title:t.name,url:t.url,closedDate:null,createdDate:new Date(e.toISOString()),author:null,updatedDate:new Date(t.dateLastActivity),assignees:t.idMembers.map(r=>({id:r,username:null,name:null,email:null,avatarUrl:null,url:null})),description:null,state:s[t.idList??""]?{id:t.idList,name:s[t.idList].name,color:null}:null,type:null,repository:null,upvoteCount:t.badges.votes,labels:t.labels.map(r=>({color:r.color,description:null,id:r.id,name:r.name}))}},te=class extends v{async getCurrentUser(s,e={}){let r=await this.config.request({url:`${e.baseUrl||k}/1/members/me?key=${s.appKey}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)});return{data:{name:r.body.fullName,email:r.body.email,avatarUrl:r.body.avatarHash?`https://trello-members.s3.amazonaws.com/${r.body.id}/${r.body.avatarHash}/50.png`:null,id:r.body.id,username:r.body.username,url:r.body.url}}}async getBoardsForCurrentUser(s,e={}){return{data:(await this.config.request({url:`${e.baseUrl||k}/1/members/me/boards?fields=name&key=${s.appKey}&token=${e.token||this.config.token}&filter=open`,headers:R(e.token||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getListsForTrelloBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||k}/1/boards/${n}/lists?key=${r}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body}}async getAccountsForTrelloBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||k}/1/boards/${n}/members?key=${r}&token=${e.token||this.config.token}`,headers:R(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 r=["-is:archived","sort:edited"],{appKey:n,boardId:o,filterText:a,assigneeLogins:i,trelloBoardListsById:u}=s||{};i&&r.push("@me");let l=`${a?`${a}`:""}${r.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${e.baseUrl||k}/1/search?key=${n}&query=${l}&cards_limit=${Es}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body.cards.map(d=>Cs(d,u||{}))}}async updateIssue(s,e,r,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||k}/1/cards/${e}?key=${s}&token=${n.token||this.config.token}&${r}`,headers:R(n.token||this.config.token)})}async setIssueStatus(s,e={}){let{appKey:r,cardId:n,status:o}=s,a=`idList=${o}`;if(!(await this.updateIssue(r,n,a,e)).body.id)throw new Error("Could not set issue status")}async setIssueAssignees(s,e={}){let{appKey:r,cardId:n,assigneeIds:o}=s,a=`idMembers=${encodeURIComponent(o.join(","))}`;if(!(await this.updateIssue(r,n,a,e)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(s,e={}){let{appKey:r,cardId:n,labelIds:o}=s;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||k}/1/cards/${n}?key=${r}&token=${e.token||this.config.token}&idLabels=${encodeURIComponent(o.join(","))}`,headers:R(e.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(s,e={}){let{appKey:r,cardId:n,archived:o}=s;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||k}/1/cards/${n}?key=${r}&token=${e.token||this.config.token}&closed=${o}`,headers:R(e.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async getLabelsForBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||k}/1/boards/${n}/labels?key=${r}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body.map(a=>({color:a.color,description:null,id:a.id,name:a.name}))}}};var be={};T(be,{getIssueUniqueId:()=>qs,getPullRequestUniqueId:()=>vs});var qs=(t,s,e,r="")=>{let n=[];return n.push(r),n.push(t),n.push(s),n.push(e),JSON.stringify(n)},vs=(t,s,e,r,n="")=>{let o=[];return o.push(n),o.push(t),o.push(s),o.push(e),o.push(r),JSON.stringify(o)};var ye={};T(ye,{getIssueUniqueId:()=>Us,getPullRequestUniqueId:()=>$s});var Us=(t,s)=>JSON.stringify(["",t,s]),$s=(t,s)=>JSON.stringify(["",t,s]);var Pe={};T(Pe,{getIssueUniqueId:()=>Ls,getPullRequestUniqueId:()=>Gs});var Ls=(t,s,e)=>JSON.stringify([e,t,s]),Gs=(t,s,e)=>JSON.stringify([e,t,s]);var we={};T(we,{CHANGES_REQUESTED_BUCKET_ID:()=>_s,CONFLICTS_BUCKET_ID:()=>xs,DRAFT_BUCKET_ID:()=>Fs,FAILING_CI_BUCKET_ID:()=>Os,NEEDS_MY_REVIEW_BUCKET_ID:()=>ks,OTHER_BUCKET_ID:()=>Bs,READY_TO_MERGE_BUCKET_ID:()=>As,REVIEWER_COMMENTED_BUCKET_ID:()=>Ns,UNASSIGNED_REVIEWERS_BUCKET_ID:()=>Ts,WAITING_FOR_REVIEW_BUCKET_ID:()=>Qs,groupPullRequestsIntoBuckets:()=>js});var A=(t,s,e,r)=>({id:t,faIconName:e,name:s,priority:r,pullRequests:[]}),As="readyToMerge",Ts="unassignedReviewers",Os="failingCI",xs="conflicts",ks="needsMyReview",_s="changesRequested",Ns="reviewerCommented",Qs="waitingForReview",Fs="draft",Bs="other",js=(t,s)=>{let e={readyToMerge:A("readyToMerge","Ready to Merge","code-merge",0),unassignedReviewers:A("unassignedReviewers","Unassigned Reviewers","user-plus",1),failingCI:A("failingCI","Failing CI","circle-x",2),conflicts:A("conflicts","Resolve Conflicts","triangle-exclamation",3),needsMyReview:A("needsMyReview","Needs My Review","eye",4),changesRequested:A("changesRequested","Suggested Changes","file-plus",5),reviewerCommented:A("reviewerCommented","Reviewer Commented","comment",6),waitingForReview:A("waitingForReview","Waiting for Review","circle-pause",7),draft:A("draft","Draft","compass-drafting",8),other:A("other","Other","ellipsis",9)};return t.forEach(r=>{var u,l,p,d,c,g,m,f;let n=!0,o=((u=r.author)==null?void 0:u.id)===s.id,a=((l=r.assignees)==null?void 0:l.some(I=>I.id===s.id))??!1,i=((p=r.reviews)==null?void 0:p.some(I=>I.reviewer.id===s.id))??!1;(o||a&&!i)&&r.mergeableState==="MERGEABLE"&&(!r.reviewDecision||r.reviewDecision==="APPROVED")&&(((d=r.permissions)==null?void 0:d.canMerge)??!0)&&(e.readyToMerge.pullRequests.push(r),n=!1),o&&!((c=r.reviews)!=null&&c.length)&&(e.unassignedReviewers.pullRequests.push(r),n=!1),o&&((m=(g=r.headCommit)==null?void 0:g.buildStatuses)!=null&&m.some(I=>I.state==="ERROR"||I.state==="FAILED"))&&(e.failingCI.pullRequests.push(r),n=!1),o&&r.mergeableState==="CONFLICTS"&&(e.conflicts.pullRequests.push(r),n=!1),(f=r.reviews)!=null&&f.some(I=>I.reviewer.id===s.id&&I.state==="REVIEW_REQUESTED")&&(e.needsMyReview.pullRequests.push(r),n=!1),o&&r.reviewDecision==="CHANGES_REQUESTED"&&(e.changesRequested.pullRequests.push(r),n=!1),o&&r.reviewDecision==="COMMENTED"&&(e.reviewerCommented.pullRequests.push(r),n=!1),o&&r.reviewDecision==="REVIEW_REQUESTED"&&(e.waitingForReview.pullRequests.push(r),n=!1),o&&r.isDraft&&(e.draft.pullRequests.push(r),n=!1),n&&e.other.pullRequests.push(r)}),e};var Se={};T(Se,{getIssueUniqueId:()=>Ms,getPullRequestRank:()=>Ws,getPullRequestUniqueId:()=>zs});var Ms=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},zs=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},Ws=(t,s,e)=>{var a,i,u;let r=0,n,o;return(a=t.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=t.author)==null?void 0:i.id)===s?r+=1e3:(u=t.assignees)!=null&&u.find(l=>l.id===s)?r+=900:n==="REVIEW_REQUESTED"?r+=800:e&&(r+=700),o==="APPROVED"?t.mergeableState==="MERGEABLE"?r+=100:t.mergeableState==="CONFLICTS"?r+=90:r+=80:o=="CHANGES_REQUESTED"&&(r+=70),r};var De={};T(De,{getIssueUniqueId:()=>Hs,getPullRequestUniqueId:()=>Js});var Hs=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},Js=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)};var Ee={};T(Ee,{getIssueUniqueId:()=>Ks,getJiraServerIssueUniqueId:()=>Vs});var Ks=(t,s,e)=>{let r=[];return r.push(""),r.push(t),r.push(s),r.push(e),JSON.stringify(r)},Vs=(t,s,e)=>{let r=[];return r.push(e),r.push(""),r.push(t),r.push(s),JSON.stringify(r)};var Ce={};T(Ce,{getIssueUniqueId:()=>Xs});var Xs=(t,s,e,r="")=>{let n=[];return n.push(r),n.push(t),n.push(s),n.push(e),JSON.stringify(n)};var Ys=t=>{let s={request:t==null?void 0:t.request};return{azureDevOps:new W({...s,...t==null?void 0:t.azureDevOps}),bitbucket:new H({...s,...t==null?void 0:t.bitbucket}),bitbucketServer:new J({...s,...t==null?void 0:t.bitbucketServer}),github:new K({...s,...t==null?void 0:t.github}),gitlab:new X({...s,...t==null?void 0:t.gitlab}),jira:new Z({...s,...t==null?void 0:t.jira}),jiraServer:new ee({...s,...t==null?void 0:t.jiraServer}),trello:new te({...s,...t==null?void 0:t.trello})}},Zs=Ys;var er={azureDevOps:be,bitbucket:ye,bitbucketServer:Pe,github:Se,gitlab:De,gitProvider:we,jira:Ee,trello:Ce};
|
|
1076
|
+
`,variables:{fullPath:`${r}/${n}`,after:o}},e);return{pageInfo:((l=(u=(i=a.body.data)==null?void 0:i.project)==null?void 0:u.labels)==null?void 0:l.pageInfo)??{endCursor:null,hasNextPage:!1},data:((g=(c=(d=(p=a.body.data)==null?void 0:p.project)==null?void 0:d.labels)==null?void 0:c.nodes)==null?void 0:g.map(tt))??[]}}};var ys="https://api.atlassian.com/ex/jira",ge=100,qt=(t,s,e)=>{var n,o,a,i;let r=t.fields.assignee;return{id:t.id,commentCount:t.fields.comment.comments.length,number:t.key,title:t.fields.summary,url:s?`${s}/browse/${t.key}`:null,closedDate:null,createdDate:new Date(t.fields.created),author:me(t.fields.creator,s,e),updatedDate:new Date(t.fields.updated),assignees:r?[me(r,s,e)]:[],description:null,repository:null,state:Ds(t.fields.status),statusTransitions:((n=t.transitions)==null?void 0:n.map(Ps))??[],components:((o=t.fields.components)==null?void 0:o.map(ws))??[],type:t.fields.issuetype.name,upvoteCount:((a=t.fields.votes)==null?void 0:a.votes)||0,labels:((i=t.fields.labels)==null?void 0:i.map(u=>({color:null,description:null,id:null,name:u})))??[]}},Ps=t=>{let s;switch(t.to.statusCategory.name){case"To Do":s="TO_DO";break;case"In Progress":s="IN_PROGRESS";break;default:s="DONE";break}return{name:t.name,id:t.id,to:{id:t.to.id,name:t.to.name,color:t.to.statusCategory.colorName,category:s}}},ws=t=>({description:t.description??null,id:t.id,name:t.name}),qs=(t,s,e)=>e&&t.name?`${s}/secure/ViewProfile.jspa?name=${encodeURIComponent(t.name)}`:`${s}/jira/people/${t.accountId}`,me=(t,s,e)=>({id:(e?t.key:t.accountId)??"",name:t.displayName,email:t.emailAddress,avatarUrl:t.avatarUrls["48x48"],username:t.displayName,url:qs(t,s,e)}),Ds=t=>{let s;switch(t.statusCategory.name){case"To Do":s="TO_DO";break;case"In Progress":s="IN_PROGRESS";break;default:s="DONE";break}return{id:t.id,name:t.name,color:t.statusCategory.colorName,category:s}},z=(t,s,e)=>e?`${s.baseUrl||ys}/${e}`:`${(s==null?void 0:s.baseUrl)||t.baseUrl}`,he=async(t,s,e,r={})=>{let{page:n,resourceId:o}=s||{},a=n??0,i=`statusCategory != Done AND (creator = currentUser() OR assignee = currentUser()
|
|
1077
|
+
OR comment ~ currentUser() OR summary ~ currentUser() OR description ~ currentUser())`,l=(await t.request({url:`${z(t,r,o)}/rest/api/2/search?jql=${i}&startAt=${a}&maxResults=${ge}&fields=${["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components"].join(",")}&expand=transitions`,headers:R(r.token||t.token)})).body.issues.map(d=>qt(d,e,!o)),p=l.length==ge;return{data:l,pageInfo:{hasNextPage:p,nextPage:p?a+l.length:null}}},fe=async(t,s,e,r={})=>{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 t.request({url:`${z(t,r,l)}/rest/api/2/search?jql=${d.join(" AND ")}&startAt=${p}&maxResults=${ge}&fields=${["assignee","comment","summary","created","creator","updated","votes","issuetype","status","labels","components"].join(",")}&expand=transitions`,headers:R(r.token||t.token)})).body.issues.map(f=>qt(f,e,!l)),m=g.length==ge;return{data:g,pageInfo:{hasNextPage:m,nextPage:m?p+g.length:null}}},Re=async(t,s,e={})=>{let{resourceId:r,issueId:n,labelNames:o}=s,a={fields:{labels:o}};await t.request({method:"PUT",url:`${z(t,e,r)}/rest/api/2/issue/${n}`,body:JSON.stringify(a),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},Ie=async(t,s,e={})=>{let{resourceId:r,issueId:n,componentIds:o}=s,a={fields:{components:o.map(i=>({id:i}))}};await t.request({method:"PUT",url:`${z(t,e,r)}/rest/api/2/issue/${n}`,body:JSON.stringify(a),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},be=async(t,s,e={})=>{let{resourceId:r,issueId:n,status:o}=s,a={transition:{id:o}};await t.request({method:"POST",url:`${z(t,e,r)}/rest/api/2/issue/${n}/transitions`,body:JSON.stringify(a),headers:{...R(e.token||t.token),"Content-Type":"application/json"}})},ye=async(t,s,e={})=>{let{resourceId:r,projectIdOrKey:n}=s,o=new URL(`${z(t,e,r)}/rest/api/2/project/${n}/components`);return{data:(await t.request({url:o.toString(),headers:R(e.token||t.token)})).body}};var Y="https://api.atlassian.com/ex/jira",rt=100,Z=class extends v{constructor(){super(...arguments);this._resourceUrlCache={}}async getResourceUrl(e,r={}){var a;let n=r.token||this.config.token;if(!n)return null;let o=this._resourceUrlCache[n];return o?o[e.resourceId]??null:(await this.getJiraResourcesForCurrentUser(r),((a=this._resourceUrlCache[n])==null?void 0:a[e.resourceId])??null)}async getCurrentUserForResource(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r),o=await this.config.request({url:`${r.baseUrl||Y}/${e.resourceId}/rest/api/2/myself`,headers:R(r.token||this.config.token)});return{data:{name:o.body.displayName,email:o.body.emailAddress,avatarUrl:o.body.avatarUrls["48x48"],id:o.body.accountId,username:o.body.displayName,url:n?`${n}/jira/people/${o.body.accountId}`:null}}}async getJiraResourcesForCurrentUser(e={}){let r=await this.config.request({url:`${e.baseUrl||"https://api.atlassian.com/"}/oauth/token/accessible-resources`,headers:R(e.token||this.config.token)}),n=e.token||this.config.token,o=n?this._resourceUrlCache[n]||{}:void 0,a=r.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,r={}){let n=new URL(`${r.baseUrl||Y}/${e.resourceId}/rest/api/2/project/search`);n.searchParams.set("maxResults",rt.toString()),e.cursor&&n.searchParams.set("startAt",e.cursor);let o=await this.config.request({url:n.toString(),headers:R(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(a=>({id:a.id,key:a.key,name:a.name,resourceId:e.resourceId}))}}async getJiraProjectsForResources(e,r={}){let n=[];return await Promise.all(e.resourceIds.map(async o=>{let a=await this.getJiraProjectsForResource({resourceId:o},r);n.push(...a.data)})),{data:n}}async getAccountsForJiraProject(e,r={}){let{resourceId:n,projectKey:o,cursor:a}=e,i=await this.getResourceUrl({resourceId:n},r),u=new URL(`${r.baseUrl||Y}/${n}/rest/api/2/user/assignable/search`);u.searchParams.set("maxResults",rt.toString()),a&&u.searchParams.set("startAt",a),u.searchParams.set("project",o);let l=await this.config.request({url:u.toString(),headers:R(r.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=>me(p,i,!1))}}async getComponentsForJiraProject(e,r={}){return await ye(this.config,e,r)}async getIssuesForProject(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r);return await fe(this.config,e,n,r)}async getIssuesForResourceForCurrentUser(e,r={}){let n=await this.getResourceUrl({resourceId:e.resourceId},r);return await he(this.config,e,n,r)}async setIssueStatus(e,r={}){await be(this.config,e,r)}async setIssueAssignee(e,r={}){let{resourceId:n,issueId:o,assigneeId:a}=e,i={accountId:a};await this.config.request({method:"PUT",url:`${r.baseUrl||Y}/${n}/rest/api/2/issue/${o}/assignee`,body:JSON.stringify(i),headers:{...R(r.token||this.config.token),"Content-Type":"application/json"}})}async setIssueComponents(e,r={}){await Ie(this.config,e,r)}async setIssueLabels(e,r={}){await Re(this.config,e,r)}async getLabelsForResource(e,r={}){let{resourceId:n,cursor:o}=e,a=new URL(`${r.baseUrl||Y}/${n}/rest/api/2/label`);a.searchParams.set("maxResults",rt.toString()),o&&a.searchParams.set("startAt",o);let i=await this.config.request({url:a.toString(),headers:R(r.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 ee=class extends L{async getCurrentUser(s={}){let e=await this.config.request({url:`${(s==null?void 0:s.baseUrl)||this.config.baseUrl}/rest/api/2/myself`,headers:R((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:R((s==null?void 0:s.token)||this.config.token)})).body.map(r=>({id:r.id,name:r.name}))}}async getIssuesForProject(s,e={}){if(!e.baseUrl)throw new Error('Jira Server requires a "baseUrl" for this function.');return await fe(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 he(this.config,s,e.baseUrl,e)}async setIssueStatus(s,e={}){await be(this.config,s,e)}async setIssueLabels(s,e={}){await Re(this.config,s,e)}async setIssueComponents(s,e={}){await Ie(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:R(s.token||this.config.token)})).body.results.map(({displayName:r})=>({color:null,description:null,id:null,name:r}))}}async getComponentsForJiraProject(s,e={}){return await ye(this.config,s,e)}};var _="https://api.trello.com",Ss=1e3,Es=(t,s)=>{let e=new Date(1e3*parseInt(t.id.substring(0,8),16));return{id:t.id,commentCount:t.badges.comments,number:t.idShort.toString(),title:t.name,url:t.url,closedDate:null,createdDate:new Date(e.toISOString()),author:null,updatedDate:new Date(t.dateLastActivity),assignees:t.idMembers.map(r=>({id:r,username:null,name:null,email:null,avatarUrl:null,url:null})),description:null,state:s[t.idList??""]?{id:t.idList,name:s[t.idList].name,color:null}:null,type:null,repository:null,upvoteCount:t.badges.votes,labels:t.labels.map(r=>({color:r.color,description:null,id:r.id,name:r.name}))}},te=class extends v{async getCurrentUser(s,e={}){let r=await this.config.request({url:`${e.baseUrl||_}/1/members/me?key=${s.appKey}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)});return{data:{name:r.body.fullName,email:r.body.email,avatarUrl:r.body.avatarHash?`https://trello-members.s3.amazonaws.com/${r.body.id}/${r.body.avatarHash}/50.png`:null,id:r.body.id,username:r.body.username,url:r.body.url}}}async getBoardsForCurrentUser(s,e={}){return{data:(await this.config.request({url:`${e.baseUrl||_}/1/members/me/boards?fields=name&key=${s.appKey}&token=${e.token||this.config.token}&filter=open`,headers:R(e.token||this.config.token)})).body.map(n=>({id:n.id,name:n.name}))}}async getListsForTrelloBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||_}/1/boards/${n}/lists?key=${r}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body}}async getAccountsForTrelloBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||_}/1/boards/${n}/members?key=${r}&token=${e.token||this.config.token}`,headers:R(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 r=["-is:archived","sort:edited"],{appKey:n,boardId:o,filterText:a,assigneeLogins:i,trelloBoardListsById:u}=s||{};i&&r.push("@me");let l=`${a?`${a}`:""}${r.join(" ")} board:${o}`;return{data:(await this.config.request({url:`${e.baseUrl||_}/1/search?key=${n}&query=${l}&cards_limit=${Ss}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body.cards.map(d=>Es(d,u||{}))}}async updateIssue(s,e,r,n){return await this.config.request({method:"PUT",url:`${n.baseUrl||_}/1/cards/${e}?key=${s}&token=${n.token||this.config.token}&${r}`,headers:R(n.token||this.config.token)})}async setIssueStatus(s,e={}){let{appKey:r,cardId:n,status:o}=s,a=`idList=${o}`;if(!(await this.updateIssue(r,n,a,e)).body.id)throw new Error("Could not set issue status")}async setIssueAssignees(s,e={}){let{appKey:r,cardId:n,assigneeIds:o}=s,a=`idMembers=${encodeURIComponent(o.join(","))}`;if(!(await this.updateIssue(r,n,a,e)).body.id)throw new Error("Could not set issue status")}async setIssueLabels(s,e={}){let{appKey:r,cardId:n,labelIds:o}=s;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||_}/1/cards/${n}?key=${r}&token=${e.token||this.config.token}&idLabels=${encodeURIComponent(o.join(","))}`,headers:R(e.token||this.config.token)})).body.id)throw new Error("Could not set issue status")}async setIssueArchived(s,e={}){let{appKey:r,cardId:n,archived:o}=s;if(!(await this.config.request({method:"PUT",url:`${e.baseUrl||_}/1/cards/${n}?key=${r}&token=${e.token||this.config.token}&closed=${o}`,headers:R(e.token||this.config.token)})).body.id)throw new Error("Could not update issue archived status")}async getLabelsForBoard(s,e={}){let{appKey:r,boardId:n}=s;return{data:(await this.config.request({url:`${e.baseUrl||_}/1/boards/${n}/labels?key=${r}&token=${e.token||this.config.token}`,headers:R(e.token||this.config.token)})).body.map(a=>({color:a.color,description:null,id:a.id,name:a.name}))}}};var Pe={};T(Pe,{getIssueUniqueId:()=>Cs,getPullRequestUniqueId:()=>vs});var Cs=(t,s,e,r="")=>{let n=[];return n.push(r),n.push(t),n.push(s),n.push(e),JSON.stringify(n)},vs=(t,s,e,r,n="")=>{let o=[];return o.push(n),o.push(t),o.push(s),o.push(e),o.push(r),JSON.stringify(o)};var we={};T(we,{getIssueUniqueId:()=>Us,getPullRequestUniqueId:()=>$s});var Us=(t,s)=>JSON.stringify(["",t,s]),$s=(t,s)=>JSON.stringify(["",t,s]);var qe={};T(qe,{getIssueUniqueId:()=>Ls,getPullRequestUniqueId:()=>Gs});var Ls=(t,s,e)=>JSON.stringify([e,t,s]),Gs=(t,s,e)=>JSON.stringify([e,t,s]);var De={};T(De,{CHANGES_REQUESTED_BUCKET_ID:()=>_s,CONFLICTS_BUCKET_ID:()=>xs,DRAFT_BUCKET_ID:()=>Fs,FAILING_CI_BUCKET_ID:()=>Os,NEEDS_MY_REVIEW_BUCKET_ID:()=>ks,OTHER_BUCKET_ID:()=>Bs,READY_TO_MERGE_BUCKET_ID:()=>As,REVIEWER_COMMENTED_BUCKET_ID:()=>Ns,UNASSIGNED_REVIEWERS_BUCKET_ID:()=>Ts,WAITING_FOR_REVIEW_BUCKET_ID:()=>Qs,groupPullRequestsIntoBuckets:()=>js});var A=(t,s,e,r)=>({id:t,faIconName:e,name:s,priority:r,pullRequests:[]}),As="readyToMerge",Ts="unassignedReviewers",Os="failingCI",xs="conflicts",ks="needsMyReview",_s="changesRequested",Ns="reviewerCommented",Qs="waitingForReview",Fs="draft",Bs="other",js=(t,s)=>{let e={readyToMerge:A("readyToMerge","Ready to Merge","code-merge",0),unassignedReviewers:A("unassignedReviewers","Unassigned Reviewers","user-plus",1),failingCI:A("failingCI","Failing CI","circle-x",2),conflicts:A("conflicts","Resolve Conflicts","triangle-exclamation",3),needsMyReview:A("needsMyReview","Needs My Review","eye",4),changesRequested:A("changesRequested","Suggested Changes","file-plus",5),reviewerCommented:A("reviewerCommented","Reviewer Commented","comment",6),waitingForReview:A("waitingForReview","Waiting for Review","circle-pause",7),draft:A("draft","Draft","compass-drafting",8),other:A("other","Other","ellipsis",9)};return t.forEach(r=>{var u,l,p,d,c,g,m,f;let n=!0,o=((u=r.author)==null?void 0:u.id)===s.id,a=((l=r.assignees)==null?void 0:l.some(I=>I.id===s.id))??!1,i=((p=r.reviews)==null?void 0:p.some(I=>I.reviewer.id===s.id))??!1;(o||a&&!i)&&r.mergeableState==="MERGEABLE"&&(!r.reviewDecision||r.reviewDecision==="APPROVED")&&(((d=r.permissions)==null?void 0:d.canMerge)??!0)&&(e.readyToMerge.pullRequests.push(r),n=!1),o&&!((c=r.reviews)!=null&&c.length)&&(e.unassignedReviewers.pullRequests.push(r),n=!1),o&&((m=(g=r.headCommit)==null?void 0:g.buildStatuses)!=null&&m.some(I=>I.state==="ERROR"||I.state==="FAILED"))&&(e.failingCI.pullRequests.push(r),n=!1),o&&r.mergeableState==="CONFLICTS"&&(e.conflicts.pullRequests.push(r),n=!1),(f=r.reviews)!=null&&f.some(I=>I.reviewer.id===s.id&&I.state==="REVIEW_REQUESTED")&&(e.needsMyReview.pullRequests.push(r),n=!1),o&&r.reviewDecision==="CHANGES_REQUESTED"&&(e.changesRequested.pullRequests.push(r),n=!1),o&&r.reviewDecision==="COMMENTED"&&(e.reviewerCommented.pullRequests.push(r),n=!1),o&&r.reviewDecision==="REVIEW_REQUESTED"&&(e.waitingForReview.pullRequests.push(r),n=!1),o&&r.isDraft&&(e.draft.pullRequests.push(r),n=!1),n&&e.other.pullRequests.push(r)}),e};var Se={};T(Se,{getIssueUniqueId:()=>Ms,getPullRequestRank:()=>Ws,getPullRequestUniqueId:()=>zs});var Ms=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},zs=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},Ws=(t,s,e)=>{var a,i,u;let r=0,n,o;return(a=t.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=t.author)==null?void 0:i.id)===s?r+=1e3:(u=t.assignees)!=null&&u.find(l=>l.id===s)?r+=900:n==="REVIEW_REQUESTED"?r+=800:e&&(r+=700),o==="APPROVED"?t.mergeableState==="MERGEABLE"?r+=100:t.mergeableState==="CONFLICTS"?r+=90:r+=80:o=="CHANGES_REQUESTED"&&(r+=70),r};var Ee={};T(Ee,{getIssueUniqueId:()=>Hs,getPullRequestUniqueId:()=>Js});var Hs=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)},Js=(t,s="")=>{let e=[];return e.push(s),e.push(t),JSON.stringify(e)};var Ce={};T(Ce,{getIssueUniqueId:()=>Ks,getJiraServerIssueUniqueId:()=>Vs});var Ks=(t,s,e)=>{let r=[];return r.push(""),r.push(t),r.push(s),r.push(e),JSON.stringify(r)},Vs=(t,s,e)=>{let r=[];return r.push(e),r.push(""),r.push(t),r.push(s),JSON.stringify(r)};var ve={};T(ve,{getIssueUniqueId:()=>Xs});var Xs=(t,s,e,r="")=>{let n=[];return n.push(r),n.push(t),n.push(s),n.push(e),JSON.stringify(n)};var Ys=t=>{let s={request:t==null?void 0:t.request};return{azureDevOps:new W({...s,...t==null?void 0:t.azureDevOps}),bitbucket:new H({...s,...t==null?void 0:t.bitbucket}),bitbucketServer:new J({...s,...t==null?void 0:t.bitbucketServer}),github:new K({...s,...t==null?void 0:t.github}),gitlab:new X({...s,...t==null?void 0:t.gitlab}),jira:new Z({...s,...t==null?void 0:t.jira}),jiraServer:new ee({...s,...t==null?void 0:t.jiraServer}),trello:new te({...s,...t==null?void 0:t.trello})}},Zs=Ys;var er={azureDevOps:Pe,bitbucket:we,bitbucketServer:qe,github:Se,gitlab:Ee,gitProvider:De,jira:Ce,trello:ve};
|
|
@@ -243,6 +243,10 @@ export interface GetReposInput {
|
|
|
243
243
|
export type GetPRsForReposInput = GetReposInput | {
|
|
244
244
|
repoIds: (string | number)[];
|
|
245
245
|
};
|
|
246
|
+
export type GetPRForRepoInput = {
|
|
247
|
+
repo: GetRepoInput;
|
|
248
|
+
number: number;
|
|
249
|
+
};
|
|
246
250
|
export interface CursorPageInput {
|
|
247
251
|
cursor?: string | null;
|
|
248
252
|
}
|
|
@@ -283,5 +287,6 @@ export interface GitProvider {
|
|
|
283
287
|
path: string;
|
|
284
288
|
}, options: Options): Promise<Result<GitBlame>>;
|
|
285
289
|
getPullRequestsForRepos?(input: GetPRsForReposInput, options: Options): Promise<Result<GitPullRequest[]>>;
|
|
290
|
+
getPullRequestForRepo?(input: GetPRForRepoInput, options: Options): Promise<Result<GitPullRequest | null>>;
|
|
286
291
|
}
|
|
287
292
|
export declare const MAX_PAGE_SIZE = 100;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { Account, CursorPageInput, EnterpriseOptions, GetRepoErrorData, GetRepoInput, GitLabel, GitMergeStrategy, GitMilestone, GitProvider, GitPullRequest, GitPullRequestReviewComment, GitRepository, Organization } from '../gitProvider';
|
|
2
3
|
import { Issue } from '../issueProvider';
|
|
3
4
|
import { EnterpriseProvider } from '../provider';
|
|
@@ -152,6 +153,13 @@ export declare class GitHub extends EnterpriseProvider implements GitProvider {
|
|
|
152
153
|
}[];
|
|
153
154
|
};
|
|
154
155
|
}>;
|
|
156
|
+
getFileContents(input: {
|
|
157
|
+
repo: GetRepoInput;
|
|
158
|
+
path: string;
|
|
159
|
+
ref: string;
|
|
160
|
+
}, options?: EnterpriseOptions): Promise<{
|
|
161
|
+
data: import("buffer").Blob;
|
|
162
|
+
}>;
|
|
155
163
|
searchPullRequests(input: {
|
|
156
164
|
query: string;
|
|
157
165
|
isDraft?: boolean;
|
|
@@ -190,6 +198,17 @@ export declare class GitHub extends EnterpriseProvider implements GitProvider {
|
|
|
190
198
|
};
|
|
191
199
|
data: GitPullRequest[];
|
|
192
200
|
}>;
|
|
201
|
+
getPullRequestForRepo(input: {
|
|
202
|
+
repo: GetRepoInput;
|
|
203
|
+
number: number;
|
|
204
|
+
}, options?: EnterpriseOptions): Promise<{
|
|
205
|
+
data: GitPullRequest | null;
|
|
206
|
+
}>;
|
|
207
|
+
getPullRequestByGraphQLId(input: {
|
|
208
|
+
graphQLId: string;
|
|
209
|
+
}, options?: EnterpriseOptions): Promise<{
|
|
210
|
+
data: GitPullRequest | null;
|
|
211
|
+
}>;
|
|
193
212
|
closePullRequest(input: {
|
|
194
213
|
pullRequestGraphQLId: string;
|
|
195
214
|
}, options?: EnterpriseOptions): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gitkraken/provider-apis",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.4",
|
|
4
4
|
"description": "An SDK around different third-party APIs that accepts and returns data in a common format.",
|
|
5
5
|
"author": "Axosoft, LLC dba GitKraken",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|