@gitkraken/provider-apis 0.29.5 → 0.29.7

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.
@@ -1 +1 @@
1
- "use strict";var Oe=Object.create;var O=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var xe=Object.getOwnPropertyNames;var ke=Object.getPrototypeOf,De=Object.prototype.hasOwnProperty;var b=(r,e)=>{for(var t in e)O(r,t,{get:e[t],enumerable:!0})},ae=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of xe(e))!De.call(r,s)&&s!==t&&O(r,s,{get:()=>e[s],enumerable:!(i=Ae(e,s))||i.enumerable});return r};var Be=(r,e,t)=>(t=r!=null?Oe(ke(r)):{},ae(e||!r||!r.__esModule?O(t,"default",{value:r,enumerable:!0}):t,r)),Se=r=>ae(O({},"__esModule",{value:!0}),r);var Xe={};b(Xe,{AzureDevopsUtils:()=>A,BitbucketServerUtils:()=>D,BitbucketUtils:()=>x,GitHubUtils:()=>$,GitLabUtils:()=>H,GitProviderUtils:()=>L,JiraUtils:()=>V,TrelloUtils:()=>J,Utils:()=>Ze});module.exports=Se(Xe);var A={};b(A,{default:()=>Ge});var Ge={};var x={};b(x,{default:()=>Ne});var Ne={};var D={};b(D,{normalizePermissions:()=>Ie,restApiPullRequestToCommonPullRequest:()=>ze});var le={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},de=r=>!r||r.length===0?null:r.reduce((e,t)=>le[t.state]>le[e]?t.state:e,"APPROVED"),k=(r,e)=>r.name||r.username||r.email||e,T=r=>{let e=Object.values(r).map(t=>t.name).sort((t,i)=>t.localeCompare(i));return Object.values(r).forEach(t=>{t.priority!==-1&&(t.priority=e.indexOf(t.name))}),r};var pe=Be(require("node-fetch")),Ue=globalThis.fetch||pe.default;var ce=r=>{let e=r.links.self[0].href;return{name:r.displayName,email:r.emailAddress,avatarUrl:r.avatarUrl??(e&&`${e}/avatar.png`),id:r.id.toString(),username:r.name,url:e}},fe=r=>{var p,c,m,I,l,P;let e={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},t={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},i=r.reviewers.map(d=>({reviewer:ce(d.user),state:t[d.status]})),s=((p=r.toRef.repository.links.clone.find(d=>d.name==="ssh"))==null?void 0:p.href)??null,n=((c=r.toRef.repository.links.clone.find(d=>d.name==="https"))==null?void 0:c.href)??null;n||(n=((m=r.toRef.repository.links.clone.find(d=>d.name==="http"))==null?void 0:m.href)??null);let u=((I=r.fromRef.repository.links.clone.find(d=>d.name==="ssh"))==null?void 0:I.href)??null,g=((l=r.fromRef.repository.links.clone.find(d=>d.name==="https"))==null?void 0:l.href)??null;return g||(g=((P=r.fromRef.repository.links.clone.find(d=>d.name==="http"))==null?void 0:P.href)??null),{id:r.id.toString(),number:r.id,title:r.title,url:r.links.self[0].href,state:e[r.state],isDraft:!1,createdDate:new Date(r.createdDate),updatedDate:new Date(r.updatedDate),closedDate:r.closedDate?new Date(r.closedDate):null,mergedDate:r.state=="MERGED"&&r.closedDate?new Date(r.closedDate):null,baseRef:{name:r.toRef.displayId,oid:r.toRef.latestCommit},headRef:{name:r.fromRef.displayId,oid:r.fromRef.latestCommit},commentCount:r.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:ce(r.author.user),assignees:null,reviews:i,reviewDecision:de(i),repository:{id:r.toRef.repository.id.toString(),name:r.toRef.repository.name,owner:{login:r.toRef.repository.project.key},remoteInfo:n&&s?{cloneUrlHTTPS:n,cloneUrlSSH:s}:null},headRepository:{id:r.fromRef.repository.id.toString(),name:r.fromRef.repository.name,owner:{login:r.fromRef.repository.project.key},remoteInfo:g&&u?{cloneUrlHTTPS:g,cloneUrlSSH:u}:null},headCommit:null,mergeableState:"MERGEABLE",permissions:null,version:r.version}};var ze=r=>fe(r),Ie=r=>r?r.find(e=>e.permission==="USER_ADMIN"||e.permission==="PROJECT_ADMIN"||e.permission==="ADMIN"||e.permission==="SYS_ADMIN"||e.permission==="REPO_ADMIN")?{canCreateWebhook:!0,canPush:!0,isAdmin:!0}:r.find(e=>e.permission==="REPO_WRITE"||e.permission==="REPO_CREATE"||e.permission==="PROJECT_CREATE"||e.permission==="PROJECT_WRITE")?{canCreateWebhook:!1,canPush:!0,isAdmin:!1}:{canCreateWebhook:!1,canPush:!1,isAdmin:!1}:{canCreateWebhook:!1,canPush:!1,isAdmin:!1};var L={};b(L,{CHANGES_REQUESTED_ACTION_CATEGORY:()=>qe,CHANGES_REQUESTED_BUCKET_ID:()=>te,CONFLICTS_ACTION_CATEGORY:()=>ve,CONFLICTS_BUCKET_ID:()=>X,DRAFT_ACTION_CATEGORY:()=>we,DRAFT_BUCKET_ID:()=>ne,FAILING_CI_ACTION_CATEGORY:()=>Re,FAILING_CI_BUCKET_ID:()=>Z,NEEDS_MY_REVIEW_ACTION_CATEGORY:()=>Ee,NEEDS_MY_REVIEW_BUCKET_ID:()=>ee,OTHER_ACTION_CATEGORY:()=>Ce,OTHER_BUCKET_ID:()=>se,PINNED_BUCKET_ID:()=>Q,READY_TO_MERGE_ACTION_CATEGORY:()=>he,READY_TO_MERGE_BUCKET_ID:()=>Y,REVIEWER_COMMENTED_ACTION_CATEGORY:()=>Pe,REVIEWER_COMMENTED_BUCKET_ID:()=>re,SNOOZED_BUCKET_ID:()=>oe,UNASSIGNED_REVIEWERS_ACTION_CATEGORY:()=>ye,UNASSIGNED_REVIEWERS_BUCKET_ID:()=>F,WAITING_FOR_REVIEW_ACTION_CATEGORY:()=>be,WAITING_FOR_REVIEW_BUCKET_ID:()=>ie,getActionablePullRequests:()=>Te,groupPullRequestsByAssignee:()=>We,groupPullRequestsByAuthor:()=>Le,groupPullRequestsByGitKrakenTeam:()=>Je,groupPullRequestsByRepo:()=>je,groupPullRequestsByReviewer:()=>$e,groupPullRequestsByWorkspace:()=>Ve,groupPullRequestsIntoBuckets:()=>_e});var B=class{constructor(){}validate(e){if(!e.organizationName)throw new Error("organizationName is required");if(!e.projectId)throw new Error("projectId is required");if(!e.entityId)throw new Error("issueId is required")}encode(e){if(this.validate(e),!e.organizationName||!e.projectId||!e.entityId)throw new Error("Missing required fields for Azure DevOps issue uniqueId");let t=[];return t.push(e.provider),t.push("issue"),t.push("1"),e.provider==="azureDevOpsServer"?t.push(e.domain):t.push(""),t.push(e.organizationName),t.push(e.projectId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<7)throw new Error("Invalid Azure DevOps issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:e[4],projectId:e[5],repoId:null,entityId:e[6]}}};var S=class{constructor(){}validate(e){if(!e.organizationName)throw new Error("organizationName is required");if(!e.projectId)throw new Error("projectId is required");if(!e.repoId)throw new Error("repoId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.organizationName||!e.projectId||!e.repoId||!e.entityId)throw new Error("Missing required fields for Azure DevOps pull request uniqueId");let t=[];return t.push(e.provider),t.push("pr"),t.push("1"),e.provider==="azureDevOpsServer"?t.push(e.domain):t.push(""),t.push(e.organizationName),t.push(e.projectId),t.push(e.repoId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<8)throw new Error("Invalid Azure DevOps pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:e[4],projectId:e[5],repoId:e[6],entityId:e[7]}}};var G=class{constructor(){}validate(e){if(!e.repoId)throw new Error("repoId is required");if(!e.entityId)throw new Error("issueId is required")}encode(e){if(this.validate(e),!e.repoId||!e.entityId)throw new Error("Missing required fields for Bitbucket DevOps issue uniqueId");let t=[];return t.push(e.provider),t.push("issue"),t.push("1"),e.provider==="bitbucketServer"?t.push(e.domain):t.push(""),t.push(e.repoId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<6)throw new Error("Invalid Bitbucket DevOps issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:e[4],entityId:e[5]}}};var N=class{constructor(){}validate(e){if(!e.repoId)throw new Error("repoId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.repoId||!e.entityId)throw new Error("Missing required fields for Bitbucket DevOps pull request uniqueId");let t=[];return t.push(e.provider),t.push("pr"),t.push("1"),e.provider==="bitbucketServer"?t.push(e.domain):t.push(""),t.push(e.repoId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<6)throw new Error("Invalid Bitbucket DevOps pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:e[4],entityId:e[5]}}};var U=class{constructor(){}validate(e){if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Github issue uniqueId");let t=[];return t.push(e.provider),t.push("issue"),t.push("1"),e.provider==="githubEnterprise"?t.push(e.domain):t.push(""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Github issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var z=class{constructor(){}validate(e){if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Github pull request uniqueId");let t=[];return t.push(e.provider),t.push("pr"),t.push("1"),e.provider==="githubEnterprise"?t.push(e.domain):t.push(""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Github pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var M=class{constructor(){}validate(e){if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Gitlab issue uniqueId");let t=[];return t.push(e.provider),t.push("issue"),t.push("1"),e.provider==="gitlabSelfHosted"?t.push(e.domain):t.push(""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Gitlab issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var _=class{constructor(){}validate(e){if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Gitlab pull request uniqueId");let t=[];return t.push(e.provider),t.push("pr"),t.push("1"),e.provider==="gitlabSelfHosted"?t.push(e.domain):t.push(""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Gitlab pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var j=class{constructor(){}validate(e){if(!e.projectId)throw new Error("projectId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.projectId||!e.entityId)throw new Error("Missing required fields for Jira issue uniqueId");let t=[];return t.push(e.provider),t.push("issue"),t.push("1"),e.provider=="jira"?(t.push(""),t.push(e.resourceId)):(t.push(e.domain),t.push("")),t.push(e.projectId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<7)throw new Error("Invalid Jira issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:e[4]==""?null:e[4],accountOrOrgId:null,organizationName:null,projectId:e[5],repoId:null,entityId:e[6]}}};var W=class{constructor(){}validate(e){if(!e.accountOrOrgId)throw new Error("accountOrOrgId is required");if(!e.projectId)throw new Error("projectId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.accountOrOrgId||!e.projectId||!e.entityId)throw new Error("Missing required fields for Trello issue uniqueId");let t=[];return t.push("trello"),t.push("issue"),t.push("1"),t.push(""),t.push(e.accountOrOrgId),t.push(e.projectId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<7)throw new Error("Invalid Trello issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:e[4],organizationName:null,projectId:e[5],repoId:null,entityId:e[6]}}};var Me=(r,e)=>{if(e!=="issue"&&e!=="pr")throw new Error("unknown entityType");switch(r){case"azure":case"azureDevOpsServer":return e==="pr"?new S:new B;case"bitbucket":case"bitbucketServer":return e==="pr"?new N:new G;case"github":case"githubEnterprise":return e==="pr"?new z:new U;case"gitlab":case"gitlabSelfHosted":return e==="pr"?new _:new M;case"jira":case"jiraServer":if(e==="pr")throw new Error("EntityType PullRequest is not valid for Jira");return new j;case"trello":if(e==="pr")throw new Error("EntityType PullRequest is not valid for Jira");return new W;default:throw new Error("unknown provider")}};var me=r=>{let e=JSON.parse(r);if(!e||!e.length)throw new Error("invalid issue unique id");return Me(e[0],e[1]).decode(e)};var R=(r,e,t,i)=>({id:r,faIconName:t,name:e,priority:i,pullRequests:[]}),Q="pinned",Y="readyToMerge",F="unassignedReviewers",Z="failingCI",X="conflicts",ee="needsMyReview",te="changesRequested",re="reviewerCommented",ie="waitingForReview",ne="draft",se="other",oe="snoozed",he="readyToMerge",ye="unassignedReviewers",Re="failingCI",ve="conflicts",Ee="needsMyReview",qe="changesRequested",Pe="reviewerCommented",be="waitingForReview",we="draft",Ce="other",Te=(r,e,t)=>r.map(i=>{var p,c,m,I,l,P,d,y,w,C,a,o,h,ue;let n={...i,...{suggestedActionCategory:Ce,priority:1e3,viewer:{canMerge:!1,isAuthor:!1,isAssignee:!1,isReviewer:!1,shouldMerge:!1,shouldAssignReviewer:!1,waitingOnReviews:!1,shouldReview:!1},failingCI:!1,hasConflicts:!1,changeRequestReviewCount:0,codeSuggestionsCount:0,commentReviewCount:0,approvalReviewCount:0}};e&&(n.viewer.isAuthor=((p=i.author)==null?void 0:p.id)===e.id,n.viewer.isAssignee=((c=i.assignees)==null?void 0:c.some(f=>f.id===e.id))??!1,n.viewer.isReviewer=((m=i.reviews)==null?void 0:m.some(f=>f.reviewer.id===e.id))??!1),n.viewer.canMerge=((I=i.permissions)==null?void 0:I.canMerge)??!0,n.hasConflicts=i.mergeableState==="CONFLICTS",n.failingCI=((P=(l=i.headCommit)==null?void 0:l.buildStatuses)==null?void 0:P.some(f=>f.state==="ERROR"||f.state==="FAILED"))||i.mergeableState==="FAILING_CHECKS",n.commentReviewCount=((d=i.reviews)==null?void 0:d.filter(f=>f.state==="COMMENTED").length)??0,n.approvalReviewCount=((y=i.reviews)==null?void 0:y.filter(f=>f.state==="APPROVED").length)??0,n.changeRequestReviewCount=((w=i.reviews)==null?void 0:w.filter(f=>f.state==="CHANGES_REQUESTED").length)??0;let u=(C=t==null?void 0:t.enrichedItemsByUniqueId)==null?void 0:C[i.uuid];u!=null&&(n.viewer.enrichedItems=u,u.some(f=>f.type==="pin")&&(n.viewer.pinned=!0,n.priority-=800),u.some(f=>f.type==="snooze")&&(n.viewer.snoozed=!0));let g=((o=(a=t==null?void 0:t.codeSuggestionsCountByPrUuid)==null?void 0:a[i.uuid])==null?void 0:o.count)||0;return g&&(n.codeSuggestionsCount=g),(!e||n.viewer.isAuthor||n.viewer.isAssignee&&!n.viewer.isReviewer)&&n.viewer.canMerge&&!n.isDraft&&!n.failingCI&&i.mergeableState==="MERGEABLE"&&(!i.reviewDecision||i.reviewDecision==="APPROVED")&&(n.viewer.shouldMerge=!0,n.suggestedActionCategory=he),(!e||n.viewer.isAuthor)&&i.isDraft&&(n.suggestedActionCategory=we),(!e||n.viewer.isAuthor)&&i.reviewDecision==="REVIEW_REQUESTED"&&(n.suggestedActionCategory=be,n.viewer.waitingOnReviews=!0),(!e||n.viewer.isAuthor)&&i.reviewDecision==="COMMENTED"&&(n.suggestedActionCategory=Pe),(!e||n.viewer.isAuthor)&&n.failingCI&&(n.suggestedActionCategory=Re),(!e||n.viewer.isAuthor)&&n.hasConflicts&&(n.suggestedActionCategory=ve),(!e||n.viewer.isAuthor)&&(i.reviewDecision==="CHANGES_REQUESTED"||n.codeSuggestionsCount>0)&&(n.suggestedActionCategory=qe),(!e||n.viewer.isAuthor)&&!((h=i.reviews)!=null&&h.length)&&(n.suggestedActionCategory=ye,n.viewer.shouldAssignReviewer=!0),e&&((ue=i.reviews)!=null&&ue.some(f=>f.reviewer.id===e.id&&f.state==="REVIEW_REQUESTED"))&&(n.suggestedActionCategory=Ee,n.viewer.shouldReview=!0),n}),_e=(r,e,t)=>{var u,g,p,c,m,I,l,P,d,y,w,C;let i={pinned:R(Q,"Pinned","thumbtack",((u=t==null?void 0:t.bucketPriorityOverride)==null?void 0:u.pinned)??-1),readyToMerge:R(Y,"Ready to Merge","code-merge",((g=t==null?void 0:t.bucketPriorityOverride)==null?void 0:g.readyToMerge)??0),unassignedReviewers:R(F,"Unassigned Reviewers","user-plus",((p=t==null?void 0:t.bucketPriorityOverride)==null?void 0:p.unassignedReviewers)??1),failingCI:R(Z,"Failing CI","circle-x",((c=t==null?void 0:t.bucketPriorityOverride)==null?void 0:c.failingCI)??2),conflicts:R(X,"Resolve Conflicts","triangle-exclamation",((m=t==null?void 0:t.bucketPriorityOverride)==null?void 0:m.conflicts)??3),needsMyReview:R(ee,"Needs My Review","eye",((I=t==null?void 0:t.bucketPriorityOverride)==null?void 0:I.needsMyReview)??4),changesRequested:R(te,"Suggested Changes","file-plus",((l=t==null?void 0:t.bucketPriorityOverride)==null?void 0:l.changesRequested)??5),reviewerCommented:R(re,"Reviewer Commented","comment",((P=t==null?void 0:t.bucketPriorityOverride)==null?void 0:P.reviewerCommented)??6),waitingForReview:R(ie,"Waiting for Review","circle-pause",((d=t==null?void 0:t.bucketPriorityOverride)==null?void 0:d.waitingForReview)??7),draft:R(ne,"Draft","compass-drafting",((y=t==null?void 0:t.bucketPriorityOverride)==null?void 0:y.draft)??8),other:R(se,"Other","ellipsis",((w=t==null?void 0:t.bucketPriorityOverride)==null?void 0:w.other)??9),snoozed:R(oe,"Snoozed","snooze",((C=t==null?void 0:t.bucketPriorityOverride)==null?void 0:C.snoozed)??10)},n=Te(r,e,t).reduce((a,o)=>(a[o.uuid]=o,a),{});return r.forEach(a=>{let o=n[a.uuid],h=!0;if(o.viewer.snoozed){i[oe].pullRequests.push(a);return}o.viewer.pinned&&i[Q].pullRequests.push(a),(!e||o.viewer.isAuthor||o.viewer.isAssignee&&!o.viewer.isReviewer)&&!o.isDraft&&o.viewer.canMerge&&o.mergeableState==="MERGEABLE"&&(!a.reviewDecision||a.reviewDecision==="APPROVED")&&(i[Y].pullRequests.push(a),h=!1),o.viewer.shouldAssignReviewer&&(i[F].pullRequests.push(a),h=!1),(!e||o.viewer.isAuthor)&&o.failingCI&&(i[Z].pullRequests.push(a),h=!1),(!e||o.viewer.isAuthor)&&o.hasConflicts&&(i[X].pullRequests.push(a),h=!1),o.viewer.shouldReview&&(i[ee].pullRequests.push(a),h=!1),(!e||o.viewer.isAuthor)&&(o.reviewDecision==="CHANGES_REQUESTED"||o.codeSuggestionsCount>0)&&(i[te].pullRequests.push(a),h=!1),(!e||o.viewer.isAuthor)&&o.reviewDecision==="COMMENTED"&&(i[re].pullRequests.push(a),h=!1),(!e||o.viewer.isAuthor)&&o.reviewDecision==="REVIEW_REQUESTED"&&(i[ie].pullRequests.push(a),h=!1),o.isDraft&&(i[ne].pullRequests.push(a),h=!1),h&&i[se].pullRequests.push(a)}),Object.values(i).forEach(a=>{a.pullRequests.sort((o,h)=>n[o.uuid].priority-n[h.uuid].priority)}),i},je=r=>{let e={};return r.forEach(t=>{let i=t.repository.id;e[i]?e[i].pullRequests.push(t):e[i]={name:t.repository.name,priority:0,pullRequests:[t],id:i}}),T(e)},We=r=>{let e="internal-no-assignees",t={[e]:{name:"No assignees",priority:-1,pullRequests:[],id:e,faIconName:"user-slash"}};return r.forEach(i=>{i.assignees&&i.assignees.length?i.assignees.forEach(s=>{let n=s.id;t[n]?t[n].pullRequests.push(i):t[n]={accountData:s,name:k(s,`Unknown Assignee ${Object.keys(t).length}`),priority:0,pullRequests:[i],id:n}}):t[e].pullRequests.push(i)}),T(t)},Le=r=>{let e="internal-no-author",t={[e]:{name:"No author",priority:-1,pullRequests:[],id:e,faIconName:"user-slash"}};return r.forEach(i=>{if(i.author){let s=i.author.id;t[s]?t[s].pullRequests.push(i):t[s]={accountData:i.author,name:k(i.author,`Unknown Author ${Object.keys(t).length}`),priority:0,pullRequests:[i],id:s}}else t[e].pullRequests.push(i)}),T(t)},$e=r=>{let e="internal-no-reviewer",t={[e]:{name:"No reviewers",priority:-1,pullRequests:[],id:e,faIconName:"user-slash"}};return r.forEach(i=>{i.reviews&&i.reviews.length?i.reviews.forEach(s=>{let n=s.reviewer.id;t[n]?t[n].pullRequests.push(i):t[n]={accountData:s.reviewer,name:k(s.reviewer,`Unknown Reviewer ${Object.keys(t).length}`),priority:0,pullRequests:[i],id:n}}):t[e].pullRequests.push(i)}),T(t)},He=r=>{var e;return r.azureProject?[`${r.azureProject}-${r.azureOrganizationId}`]:((e=r.providerData)==null?void 0:e.repositories.nodes.map(t=>`${r.provider}-${t.repositoryId}`))??[]},Ve=(r,e)=>{let t="internal-no-workspace",i={[t]:{name:"No workspace",priority:-1,pullRequests:[],id:t,faIconName:"folder-xmark"}};if(e.length){let s=e.reduce((n,u)=>(He(u).forEach(p=>{n[p]?n[p].push(u):n[p]=[u]}),n),{});r.forEach(n=>{let{provider:u}=me(n.uuid),g=u==="github"?n.repository.graphQLId:n.repository.id,p=u==="azure"?[`${u}-${g}`,`${n.repository.project}-${n.repository.owner.login}`]:[`${u}-${g}`],c=!1,m=p.reduce((I,l)=>s[l]?I.concat(s[l]):I,[]);m!=null&&m.length&&m.forEach(I=>{c=!0;let l=I.id;i[l]?i[l].pullRequests.push(n):i[l]={name:I.name,priority:0,pullRequests:[n],id:l,faIconName:"folder"}}),c||i[t].pullRequests.push(n)})}else i[t].pullRequests=r;return T(i)},Je=(r,e,t,i)=>{let s="internal-no-team",n={[s]:{name:"No team",priority:-1,pullRequests:[],id:s}};return i.length?r.forEach(u=>{var c,m,I;let g=!1,p=new Set;p.add((c=u.author)==null?void 0:c.id),(m=u.assignees)==null||m.forEach(l=>p.add(l.id)),(I=u.reviews)==null||I.forEach(l=>p.add(l.reviewer.id)),i.forEach(l=>{var d;if((d=l.members)==null?void 0:d.some(y=>{var C,a;let w=(a=(C=e[y.id])==null?void 0:C[t])==null?void 0:a.providerID;return w&&p.has(w)})){g=!0;let y=l.id;n[y]?n[y].pullRequests.push(u):n[y]={name:l.name,priority:0,pullRequests:[u],id:y,teamData:l}}}),g||n[s].pullRequests.push(u)}):n[s].pullRequests=r,T(n)};var $={};b($,{getPullRequestRank:()=>Ke});var Ke=(r,e,t)=>{var u,g,p;let i=0,s,n;return(u=r.reviews)==null||u.forEach(c=>{c.reviewer.id===e&&(s=c.state),c.state==="CHANGES_REQUESTED"?n="CHANGES_REQUESTED":c.state==="APPROVED"&&n!=="CHANGES_REQUESTED"&&(n="APPROVED")}),n||(n="REVIEW_REQUESTED"),((g=r.author)==null?void 0:g.id)===e?i+=1e3:(p=r.assignees)!=null&&p.find(c=>c.id===e)?i+=900:s==="REVIEW_REQUESTED"?i+=800:t&&(i+=700),n==="APPROVED"?r.mergeableState==="MERGEABLE"?i+=100:r.mergeableState==="CONFLICTS"?i+=90:i+=80:n=="CHANGES_REQUESTED"&&(i+=70),i};var H={};b(H,{default:()=>Qe});var Qe={};var V={};b(V,{default:()=>Ye});var Ye={};var J={};b(J,{default:()=>Fe});var Fe={};var Ze={azureDevOps:A,bitbucket:x,bitbucketServer:D,github:$,gitlab:H,gitProvider:L,jira:V,trello:J};
1
+ "use strict";var Ae=Object.create;var A=Object.defineProperty;var Oe=Object.getOwnPropertyDescriptor;var xe=Object.getOwnPropertyNames;var ke=Object.getPrototypeOf,De=Object.prototype.hasOwnProperty;var b=(r,e)=>{for(var t in e)A(r,t,{get:e[t],enumerable:!0})},ae=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of xe(e))!De.call(r,s)&&s!==t&&A(r,s,{get:()=>e[s],enumerable:!(i=Oe(e,s))||i.enumerable});return r};var Be=(r,e,t)=>(t=r!=null?Ae(ke(r)):{},ae(e||!r||!r.__esModule?A(t,"default",{value:r,enumerable:!0}):t,r)),Se=r=>ae(A({},"__esModule",{value:!0}),r);var Xe={};b(Xe,{AzureDevopsUtils:()=>O,BitbucketServerUtils:()=>D,BitbucketUtils:()=>x,GitHubUtils:()=>$,GitLabUtils:()=>V,GitProviderUtils:()=>L,JiraUtils:()=>H,TrelloUtils:()=>J,Utils:()=>Ze});module.exports=Se(Xe);var O={};b(O,{default:()=>Ge});var Ge={};var x={};b(x,{default:()=>Ne});var Ne={};var D={};b(D,{normalizePermissions:()=>me,restApiPullRequestToCommonPullRequest:()=>ze});var le={APPROVED:0,COMMENTED:1,REVIEW_REQUESTED:2,CHANGES_REQUESTED:3},de=r=>!r||r.length===0?null:r.reduce((e,t)=>le[t.state]>le[e]?t.state:e,"APPROVED"),k=(r,e)=>r.name||r.username||r.email||e,T=r=>{let e=Object.values(r).map(t=>t.name).sort((t,i)=>t.localeCompare(i));return Object.values(r).forEach(t=>{t.priority!==-1&&(t.priority=e.indexOf(t.name))}),r};var pe=Be(require("node-fetch")),Ue=globalThis.fetch||pe.default;var ce=r=>{let e=r.links.self[0].href;return{name:r.displayName,email:r.emailAddress,avatarUrl:r.avatarUrl??(e&&`${e}/avatar.png`),id:r.id.toString(),username:r.name,url:e}},fe=r=>{var p,c,I,m,l,q;let e={OPEN:"OPEN",MERGED:"MERGED",DECLINED:"CLOSED"},t={UNAPPROVED:"REVIEW_REQUESTED",NEEDS_WORK:"CHANGES_REQUESTED",APPROVED:"APPROVED"},i=r.reviewers.map(d=>({reviewer:ce(d.user),state:t[d.status]})),s=((p=r.toRef.repository.links.clone.find(d=>d.name==="ssh"))==null?void 0:p.href)??null,n=((c=r.toRef.repository.links.clone.find(d=>d.name==="https"))==null?void 0:c.href)??null;n||(n=((I=r.toRef.repository.links.clone.find(d=>d.name==="http"))==null?void 0:I.href)??null);let u=((m=r.fromRef.repository.links.clone.find(d=>d.name==="ssh"))==null?void 0:m.href)??null,g=((l=r.fromRef.repository.links.clone.find(d=>d.name==="https"))==null?void 0:l.href)??null;return g||(g=((q=r.fromRef.repository.links.clone.find(d=>d.name==="http"))==null?void 0:q.href)??null),{id:r.id.toString(),number:r.id,title:r.title,url:r.links.self[0].href,state:e[r.state],isDraft:!1,createdDate:new Date(r.createdDate),updatedDate:new Date(r.updatedDate),closedDate:r.closedDate?new Date(r.closedDate):null,mergedDate:r.state=="MERGED"&&r.closedDate?new Date(r.closedDate):null,baseRef:{name:r.toRef.displayId,oid:r.toRef.latestCommit},headRef:{name:r.fromRef.displayId,oid:r.fromRef.latestCommit},commentCount:r.properties.commentCount,upvoteCount:null,commitCount:null,fileCount:null,additions:null,deletions:null,author:ce(r.author.user),assignees:null,reviews:i,reviewDecision:de(i),repository:{id:r.toRef.repository.id.toString(),name:r.toRef.repository.name,owner:{login:r.toRef.repository.project.key},remoteInfo:n&&s?{cloneUrlHTTPS:n,cloneUrlSSH:s}:null},headRepository:{id:r.fromRef.repository.id.toString(),name:r.fromRef.repository.name,owner:{login:r.fromRef.repository.project.key},remoteInfo:g&&u?{cloneUrlHTTPS:g,cloneUrlSSH:u}:null},headCommit:null,mergeableState:"MERGEABLE",permissions:null,version:r.version}};var ze=r=>fe(r),me=r=>r?r.find(e=>e.permission==="USER_ADMIN"||e.permission==="PROJECT_ADMIN"||e.permission==="ADMIN"||e.permission==="SYS_ADMIN"||e.permission==="REPO_ADMIN")?{canCreateWebhook:!0,canPush:!0,isAdmin:!0}:r.find(e=>e.permission==="REPO_WRITE"||e.permission==="REPO_CREATE"||e.permission==="PROJECT_CREATE"||e.permission==="PROJECT_WRITE")?{canCreateWebhook:!1,canPush:!0,isAdmin:!1}:{canCreateWebhook:!1,canPush:!1,isAdmin:!1}:{canCreateWebhook:!1,canPush:!1,isAdmin:!1};var L={};b(L,{CHANGES_REQUESTED_ACTION_CATEGORY:()=>Pe,CHANGES_REQUESTED_BUCKET_ID:()=>te,CONFLICTS_ACTION_CATEGORY:()=>ve,CONFLICTS_BUCKET_ID:()=>X,DRAFT_ACTION_CATEGORY:()=>we,DRAFT_BUCKET_ID:()=>ne,FAILING_CI_ACTION_CATEGORY:()=>Re,FAILING_CI_BUCKET_ID:()=>Z,NEEDS_MY_REVIEW_ACTION_CATEGORY:()=>Ee,NEEDS_MY_REVIEW_BUCKET_ID:()=>ee,OTHER_ACTION_CATEGORY:()=>Ce,OTHER_BUCKET_ID:()=>se,PINNED_BUCKET_ID:()=>Q,READY_TO_MERGE_ACTION_CATEGORY:()=>he,READY_TO_MERGE_BUCKET_ID:()=>Y,REVIEWER_COMMENTED_ACTION_CATEGORY:()=>qe,REVIEWER_COMMENTED_BUCKET_ID:()=>re,SNOOZED_BUCKET_ID:()=>oe,UNASSIGNED_REVIEWERS_ACTION_CATEGORY:()=>ye,UNASSIGNED_REVIEWERS_BUCKET_ID:()=>F,WAITING_FOR_REVIEW_ACTION_CATEGORY:()=>be,WAITING_FOR_REVIEW_BUCKET_ID:()=>ie,getActionablePullRequests:()=>Te,groupPullRequestsByAssignee:()=>We,groupPullRequestsByAuthor:()=>Le,groupPullRequestsByGitKrakenTeam:()=>Je,groupPullRequestsByRepo:()=>je,groupPullRequestsByReviewer:()=>$e,groupPullRequestsByWorkspace:()=>He,groupPullRequestsIntoBuckets:()=>_e});var B=class{constructor(){}validate(e){if(!e.organizationName)throw new Error("organizationName is required");if(!e.projectId)throw new Error("projectId is required");if(!e.entityId)throw new Error("issueId is required")}encode(e){if(this.validate(e),!e.organizationName||!e.projectId||!e.entityId)throw new Error("Missing required fields for Azure DevOps issue uniqueId");let t=[];return t.push(e.provider),t.push("issue"),t.push("1"),e.provider==="azureDevOpsServer"?t.push(e.domain):t.push(""),t.push(e.organizationName),t.push(e.projectId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<7)throw new Error("Invalid Azure DevOps issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:e[4],projectId:e[5],repoId:null,entityId:e[6]}}};var S=class{constructor(){}validate(e){if(!e.organizationName)throw new Error("organizationName is required");if(!e.projectId)throw new Error("projectId is required");if(!e.repoId)throw new Error("repoId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.organizationName||!e.projectId||!e.repoId||!e.entityId)throw new Error("Missing required fields for Azure DevOps pull request uniqueId");let t=[];return t.push(e.provider),t.push("pr"),t.push("1"),e.provider==="azureDevOpsServer"?t.push(e.domain):t.push(""),t.push(e.organizationName),t.push(e.projectId),t.push(e.repoId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<8)throw new Error("Invalid Azure DevOps pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:e[4],projectId:e[5],repoId:e[6],entityId:e[7]}}};var G=class{constructor(){}validate(e){if(!e.repoId)throw new Error("repoId is required");if(!e.entityId)throw new Error("issueId is required")}encode(e){if(this.validate(e),!e.repoId||!e.entityId)throw new Error("Missing required fields for Bitbucket DevOps issue uniqueId");let t=[];return t.push(e.provider),t.push("issue"),t.push("1"),e.provider==="bitbucketServer"?t.push(e.domain):t.push(""),t.push(e.repoId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<6)throw new Error("Invalid Bitbucket DevOps issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:e[4],entityId:e[5]}}};var N=class{constructor(){}validate(e){if(!e.repoId)throw new Error("repoId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.repoId||!e.entityId)throw new Error("Missing required fields for Bitbucket DevOps pull request uniqueId");let t=[];return t.push(e.provider),t.push("pr"),t.push("1"),e.provider==="bitbucketServer"?t.push(e.domain):t.push(""),t.push(e.repoId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<6)throw new Error("Invalid Bitbucket DevOps pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:e[4],entityId:e[5]}}};var U=class{constructor(){}validate(e){if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Github issue uniqueId");let t=[];return t.push(e.provider),t.push("issue"),t.push("1"),e.provider==="githubEnterprise"?t.push(e.domain):t.push(""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Github issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var z=class{constructor(){}validate(e){if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Github pull request uniqueId");let t=[];return t.push(e.provider),t.push("pr"),t.push("1"),e.provider==="githubEnterprise"?t.push(e.domain):t.push(""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Github pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var M=class{constructor(){}validate(e){if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Gitlab issue uniqueId");let t=[];return t.push(e.provider),t.push("issue"),t.push("1"),e.provider==="gitlabSelfHosted"?t.push(e.domain):t.push(""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Gitlab issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var _=class{constructor(){}validate(e){if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.entityId)throw new Error("Missing required fields for Gitlab pull request uniqueId");let t=[];return t.push(e.provider),t.push("pr"),t.push("1"),e.provider==="gitlabSelfHosted"?t.push(e.domain):t.push(""),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<5)throw new Error("Invalid Gitlab pull request uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:null,organizationName:null,projectId:null,repoId:null,entityId:e[4]}}};var j=class{constructor(){}validate(e){if(!e.projectId)throw new Error("projectId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.projectId||!e.entityId)throw new Error("Missing required fields for Jira issue uniqueId");let t=[];return t.push(e.provider),t.push("issue"),t.push("1"),e.provider=="jira"?(t.push(""),t.push(e.resourceId)):(t.push(e.domain),t.push("")),t.push(e.projectId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<7)throw new Error("Invalid Jira issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:e[4]==""?null:e[4],accountOrOrgId:null,organizationName:null,projectId:e[5],repoId:null,entityId:e[6]}}};var W=class{constructor(){}validate(e){if(!e.accountOrOrgId)throw new Error("accountOrOrgId is required");if(!e.projectId)throw new Error("projectId is required");if(!e.entityId)throw new Error("entityId is required")}encode(e){if(this.validate(e),!e.accountOrOrgId||!e.projectId||!e.entityId)throw new Error("Missing required fields for Trello issue uniqueId");let t=[];return t.push("trello"),t.push("issue"),t.push("1"),t.push(""),t.push(e.accountOrOrgId),t.push(e.projectId),t.push(e.entityId),JSON.stringify(t)}decode(e){if(e.length<7)throw new Error("Invalid Trello issue uniqueId, check version");return{provider:e[0],entityType:e[1],version:e[2],domain:e[3]==""?null:e[3],resourceId:null,accountOrOrgId:e[4],organizationName:null,projectId:e[5],repoId:null,entityId:e[6]}}};var Me=(r,e)=>{if(e!=="issue"&&e!=="pr")throw new Error("unknown entityType");switch(r){case"azure":case"azureDevOpsServer":return e==="pr"?new S:new B;case"bitbucket":case"bitbucketServer":return e==="pr"?new N:new G;case"github":case"githubEnterprise":return e==="pr"?new z:new U;case"gitlab":case"gitlabSelfHosted":return e==="pr"?new _:new M;case"jira":case"jiraServer":if(e==="pr")throw new Error("EntityType PullRequest is not valid for Jira");return new j;case"trello":if(e==="pr")throw new Error("EntityType PullRequest is not valid for Jira");return new W;default:throw new Error("unknown provider")}};var Ie=r=>{let e=JSON.parse(r);if(!e||!e.length)throw new Error("invalid issue unique id");return Me(e[0],e[1]).decode(e)};var R=(r,e,t,i)=>({id:r,faIconName:t,name:e,priority:i,pullRequests:[]}),Q="pinned",Y="readyToMerge",F="unassignedReviewers",Z="failingCI",X="conflicts",ee="needsMyReview",te="changesRequested",re="reviewerCommented",ie="waitingForReview",ne="draft",se="other",oe="snoozed",he="readyToMerge",ye="unassignedReviewers",Re="failingCI",ve="conflicts",Ee="needsMyReview",Pe="changesRequested",qe="reviewerCommented",be="waitingForReview",we="draft",Ce="other",Te=(r,e,t)=>r.map(i=>{var p,c,I,m,l,q,d,y,w,C,a,o,h,ue;let n={...i,...{suggestedActionCategory:Ce,priority:1e3,viewer:{canMerge:!1,isAuthor:!1,isAssignee:!1,isReviewer:!1,shouldMerge:!1,shouldAssignReviewer:!1,waitingOnReviews:!1,shouldReview:!1},failingCI:!1,hasConflicts:!1,changeRequestReviewCount:0,codeSuggestionsCount:0,commentReviewCount:0,approvalReviewCount:0}};e&&(n.viewer.isAuthor=((p=i.author)==null?void 0:p.id)===e.id,n.viewer.isAssignee=((c=i.assignees)==null?void 0:c.some(f=>f.id===e.id))??!1,n.viewer.isReviewer=((I=i.reviews)==null?void 0:I.some(f=>f.reviewer.id===e.id))??!1),n.viewer.canMerge=((m=i.permissions)==null?void 0:m.canMerge)??!0,n.hasConflicts=i.mergeableState==="CONFLICTS",n.failingCI=((q=(l=i.headCommit)==null?void 0:l.buildStatuses)==null?void 0:q.some(f=>f.state==="ERROR"||f.state==="FAILED"))||i.mergeableState==="FAILING_CHECKS",n.commentReviewCount=((d=i.reviews)==null?void 0:d.filter(f=>f.state==="COMMENTED").length)??0,n.approvalReviewCount=((y=i.reviews)==null?void 0:y.filter(f=>f.state==="APPROVED").length)??0,n.changeRequestReviewCount=((w=i.reviews)==null?void 0:w.filter(f=>f.state==="CHANGES_REQUESTED").length)??0;let u=(C=t==null?void 0:t.enrichedItemsByUniqueId)==null?void 0:C[i.uuid];u!=null&&(n.viewer.enrichedItems=u,u.some(f=>f.type==="pin")&&(n.viewer.pinned=!0,n.priority-=800),u.some(f=>f.type==="snooze")&&(n.viewer.snoozed=!0));let g=((o=(a=t==null?void 0:t.codeSuggestionsCountByPrUuid)==null?void 0:a[i.uuid])==null?void 0:o.count)||0;return g&&(n.codeSuggestionsCount=g),(!e||n.viewer.isAuthor||n.viewer.isAssignee&&!n.viewer.isReviewer)&&n.viewer.canMerge&&!n.isDraft&&!n.failingCI&&i.mergeableState==="MERGEABLE"&&(!i.reviewDecision||i.reviewDecision==="APPROVED")&&(n.viewer.shouldMerge=!0,n.suggestedActionCategory=he),(!e||n.viewer.isAuthor)&&i.isDraft&&(n.suggestedActionCategory=we),(!e||n.viewer.isAuthor)&&i.reviewDecision==="REVIEW_REQUESTED"&&(n.suggestedActionCategory=be,n.viewer.waitingOnReviews=!0),(!e||n.viewer.isAuthor)&&i.reviewDecision==="COMMENTED"&&(n.suggestedActionCategory=qe),(!e||n.viewer.isAuthor)&&n.failingCI&&(n.suggestedActionCategory=Re),(!e||n.viewer.isAuthor)&&n.hasConflicts&&(n.suggestedActionCategory=ve),(!e||n.viewer.isAuthor)&&(i.reviewDecision==="CHANGES_REQUESTED"||n.codeSuggestionsCount>0)&&(n.suggestedActionCategory=Pe),(!e||n.viewer.isAuthor)&&!((h=i.reviews)!=null&&h.length)&&(n.suggestedActionCategory=ye,n.viewer.shouldAssignReviewer=!0),e&&((ue=i.reviews)!=null&&ue.some(f=>f.reviewer.id===e.id&&f.state==="REVIEW_REQUESTED"))&&(n.suggestedActionCategory=Ee,n.viewer.shouldReview=!0),n}),_e=(r,e,t)=>{var u,g,p,c,I,m,l,q,d,y,w,C;let i={pinned:R(Q,"Pinned","thumbtack",((u=t==null?void 0:t.bucketPriorityOverride)==null?void 0:u.pinned)??-1),readyToMerge:R(Y,"Ready to Merge","code-merge",((g=t==null?void 0:t.bucketPriorityOverride)==null?void 0:g.readyToMerge)??0),unassignedReviewers:R(F,"Unassigned Reviewers","user-plus",((p=t==null?void 0:t.bucketPriorityOverride)==null?void 0:p.unassignedReviewers)??1),failingCI:R(Z,"Failing CI","circle-x",((c=t==null?void 0:t.bucketPriorityOverride)==null?void 0:c.failingCI)??2),conflicts:R(X,"Resolve Conflicts","triangle-exclamation",((I=t==null?void 0:t.bucketPriorityOverride)==null?void 0:I.conflicts)??3),needsMyReview:R(ee,"Needs My Review","eye",((m=t==null?void 0:t.bucketPriorityOverride)==null?void 0:m.needsMyReview)??4),changesRequested:R(te,"Suggested Changes","file-plus",((l=t==null?void 0:t.bucketPriorityOverride)==null?void 0:l.changesRequested)??5),reviewerCommented:R(re,"Reviewer Commented","comment",((q=t==null?void 0:t.bucketPriorityOverride)==null?void 0:q.reviewerCommented)??6),waitingForReview:R(ie,"Waiting for Review","circle-pause",((d=t==null?void 0:t.bucketPriorityOverride)==null?void 0:d.waitingForReview)??7),draft:R(ne,"Draft","compass-drafting",((y=t==null?void 0:t.bucketPriorityOverride)==null?void 0:y.draft)??8),other:R(se,"Other","ellipsis",((w=t==null?void 0:t.bucketPriorityOverride)==null?void 0:w.other)??9),snoozed:R(oe,"Snoozed","snooze",((C=t==null?void 0:t.bucketPriorityOverride)==null?void 0:C.snoozed)??10)},n=Te(r,e,t).reduce((a,o)=>(a[o.uuid]=o,a),{});return r.forEach(a=>{let o=n[a.uuid],h=!0;if(o.viewer.snoozed){i[oe].pullRequests.push(a);return}o.viewer.pinned&&i[Q].pullRequests.push(a),(!e||o.viewer.isAuthor||o.viewer.isAssignee&&!o.viewer.isReviewer)&&!o.isDraft&&o.viewer.canMerge&&o.mergeableState==="MERGEABLE"&&(!a.reviewDecision||a.reviewDecision==="APPROVED")&&(i[Y].pullRequests.push(a),h=!1),o.viewer.shouldAssignReviewer&&(i[F].pullRequests.push(a),h=!1),(!e||o.viewer.isAuthor)&&o.failingCI&&(i[Z].pullRequests.push(a),h=!1),(!e||o.viewer.isAuthor)&&o.hasConflicts&&(i[X].pullRequests.push(a),h=!1),o.viewer.shouldReview&&(i[ee].pullRequests.push(a),h=!1),(!e||o.viewer.isAuthor)&&(o.reviewDecision==="CHANGES_REQUESTED"||o.codeSuggestionsCount>0)&&(i[te].pullRequests.push(a),h=!1),(!e||o.viewer.isAuthor)&&o.reviewDecision==="COMMENTED"&&(i[re].pullRequests.push(a),h=!1),(!e||o.viewer.isAuthor)&&o.reviewDecision==="REVIEW_REQUESTED"&&(i[ie].pullRequests.push(a),h=!1),o.isDraft&&(i[ne].pullRequests.push(a),h=!1),h&&i[se].pullRequests.push(a)}),Object.values(i).forEach(a=>{a.pullRequests.sort((o,h)=>n[o.uuid].priority-n[h.uuid].priority)}),i},je=r=>{let e={};return r.forEach(t=>{let i=t.repository.id;e[i]?e[i].pullRequests.push(t):e[i]={name:t.repository.name,priority:0,pullRequests:[t],id:i}}),T(e)},We=r=>{let e="internal-no-assignees",t={[e]:{name:"No assignees",priority:-1,pullRequests:[],id:e,faIconName:"user-slash"}};return r.forEach(i=>{i.assignees&&i.assignees.length?i.assignees.forEach(s=>{let n=s.id;t[n]?t[n].pullRequests.push(i):t[n]={accountData:s,name:k(s,`Unknown Assignee ${Object.keys(t).length}`),priority:0,pullRequests:[i],id:n}}):t[e].pullRequests.push(i)}),T(t)},Le=r=>{let e="internal-no-author",t={[e]:{name:"No author",priority:-1,pullRequests:[],id:e,faIconName:"user-slash"}};return r.forEach(i=>{if(i.author){let s=i.author.id;t[s]?t[s].pullRequests.push(i):t[s]={accountData:i.author,name:k(i.author,`Unknown Author ${Object.keys(t).length}`),priority:0,pullRequests:[i],id:s}}else t[e].pullRequests.push(i)}),T(t)},$e=r=>{let e="internal-no-reviewer",t={[e]:{name:"No reviewers",priority:-1,pullRequests:[],id:e,faIconName:"user-slash"}};return r.forEach(i=>{i.reviews&&i.reviews.length?i.reviews.forEach(s=>{let n=s.reviewer.id;t[n]?t[n].pullRequests.push(i):t[n]={accountData:s.reviewer,name:k(s.reviewer,`Unknown Reviewer ${Object.keys(t).length}`),priority:0,pullRequests:[i],id:n}}):t[e].pullRequests.push(i)}),T(t)},Ve=r=>{var e;return r.azureProject?[`${r.azureProject}-${r.azureOrganizationId}`]:((e=r.providerData)==null?void 0:e.repositories.nodes.map(t=>`${r.provider}-${t.repositoryId}`))??[]},He=(r,e)=>{let t="internal-no-workspace",i={[t]:{name:"No workspace",priority:-1,pullRequests:[],id:t,faIconName:"folder-xmark"}};if(e.length){let s=e.reduce((n,u)=>(Ve(u).forEach(p=>{n[p]?n[p].push(u):n[p]=[u]}),n),{});r.forEach(n=>{let{provider:u}=Ie(n.uuid),g=u==="github"?n.repository.graphQLId:n.repository.id,p=u==="azure"?[`${u}-${g}`,`${n.repository.project}-${n.repository.owner.login}`]:[`${u}-${g}`],c=!1,I=p.reduce((m,l)=>s[l]?m.concat(s[l]):m,[]);I!=null&&I.length&&I.forEach(m=>{c=!0;let l=m.id;i[l]?i[l].pullRequests.push(n):i[l]={name:m.name,priority:0,pullRequests:[n],id:l,faIconName:"folder"}}),c||i[t].pullRequests.push(n)})}else i[t].pullRequests=r;return T(i)},Je=(r,e,t,i)=>{let s="internal-no-team",n={[s]:{name:"No team",priority:-1,pullRequests:[],id:s}};return i.length?r.forEach(u=>{var c,I,m;let g=!1,p=new Set;p.add((c=u.author)==null?void 0:c.id),(I=u.assignees)==null||I.forEach(l=>p.add(l.id)),(m=u.reviews)==null||m.forEach(l=>p.add(l.reviewer.id)),i.forEach(l=>{var d;if((d=l.members)==null?void 0:d.some(y=>{var C,a;let w=(a=(C=e[y.id])==null?void 0:C[t])==null?void 0:a.providerID;return w&&p.has(w)})){g=!0;let y=l.id;n[y]?n[y].pullRequests.push(u):n[y]={name:l.name,priority:0,pullRequests:[u],id:y,teamData:l}}}),g||n[s].pullRequests.push(u)}):n[s].pullRequests=r,T(n)};var $={};b($,{getPullRequestRank:()=>Ke});var Ke=(r,e,t)=>{var u,g,p;let i=0,s,n;return(u=r.reviews)==null||u.forEach(c=>{c.reviewer.id===e&&(s=c.state),c.state==="CHANGES_REQUESTED"?n="CHANGES_REQUESTED":c.state==="APPROVED"&&n!=="CHANGES_REQUESTED"&&(n="APPROVED")}),n||(n="REVIEW_REQUESTED"),((g=r.author)==null?void 0:g.id)===e?i+=1e3:(p=r.assignees)!=null&&p.find(c=>c.id===e)?i+=900:s==="REVIEW_REQUESTED"?i+=800:t&&(i+=700),n==="APPROVED"?r.mergeableState==="MERGEABLE"?i+=100:r.mergeableState==="CONFLICTS"?i+=90:i+=80:n=="CHANGES_REQUESTED"&&(i+=70),i};var V={};b(V,{default:()=>Qe});var Qe={};var H={};b(H,{default:()=>Ye});var Ye={};var J={};b(J,{default:()=>Fe});var Fe={};var Ze={azureDevOps:O,bitbucket:x,bitbucketServer:D,github:$,gitlab:V,gitProvider:L,jira:H,trello:J};