@@ -10,6 +10,7 @@ import {
1010 GITHUB_QUOTA ,
1111 Project ,
1212 getAllRepositoriesInProject ,
13+ getProjectIterationIssues ,
1314} from "./graphql" ;
1415import { fetchGithubDataUsingGraphql , fetchRateLimit } from "./functions/fetch" ;
1516import { createPinoLogger } from "@bogeychan/elysia-logger" ;
@@ -18,6 +19,7 @@ import { guardEndpoints } from "../plugins";
1819import {
1920 GITHUB_ACCOUNT_SCOPES ,
2021 GITHUB_AUTHENTICATION_STRATEGY_OPTIONS ,
22+ GITHUB_ITERATION_SCOPES ,
2123 GITHUB_MILESTONE_ISSUE_STATES ,
2224 GITHUB_PROJECT_SCOPES ,
2325 GITHUB_REPOSITORY_SCOPES ,
@@ -26,6 +28,7 @@ import {
2628} from "../github/types" ;
2729import {
2830 GITHUB_ACCOUNT_PARAMS ,
31+ GITHUB_ITERATION_PARAMS ,
2932 GITHUB_PROJECT_PARAMS ,
3033 GITHUB_REPOSITORY_PARAMS ,
3134} from "./params" ;
@@ -50,17 +53,17 @@ export const GITHUB_APP_WEBHOOKS = new Elysia({ prefix: "/webhooks" }).post(
5053 "" ,
5154 async ( ctx ) => {
5255 const child = log . child ( ctx ) ;
53- if ( DEV_MODE ) child . info ( "webhook received" ) ;
54-
56+ if ( DEV_MODE ) child . info ( "webhook received" ) ;
57+
5558 const eventType = ctx . headers [ "x-github-event" ] as keyof WebhookEventMap ;
56-
59+
5760 if ( eventType === "projects_v2_item" ) {
5861 if ( DEV_MODE ) log . info ( "projects_v2_item webhook received" ) ;
5962
6063 const payload = ctx . body as ProjectsV2ItemEvent ;
61-
64+
6265 if (
63- ( payload . action === "edited" || payload . action === "created" || payload . action === "converted" || payload . action === "restored" ) &&
66+ ( payload . action === "edited" || payload . action === "created" || payload . action === "converted" || payload . action === "restored" ) &&
6467 "changes" in payload &&
6568 "field_value" in payload . changes &&
6669 payload . changes ?. field_value ?. field_type === "iteration" &&
@@ -69,8 +72,8 @@ export const GITHUB_APP_WEBHOOKS = new Elysia({ prefix: "/webhooks" }).post(
6972 ) {
7073 const octokit = await getOctokitObject (
7174 GITHUB_AUTHENTICATION_STRATEGY_OPTIONS . APP ,
72- payload . installation . id ,
73- ctx . set
75+ payload . installation . id ,
76+ ctx . set
7477 ) ;
7578
7679 const fieldValue = await octokit . graphql ( `
@@ -93,19 +96,19 @@ export const GITHUB_APP_WEBHOOKS = new Elysia({ prefix: "/webhooks" }).post(
9396
9497 const result = await handleProjectItemChange ( octokit , {
9598 id : payload . projects_v2_item . node_id ,
96- content : {
99+ content : {
97100 id : payload . projects_v2_item . content_node_id
98101 } ,
99102 fieldValues : {
100103 nodes : [ {
101- field : {
104+ field : {
102105 name : "Sprint"
103106 } ,
104107 value : fieldValue . node . fieldValueByName ?. title || null
105108 } ]
106109 } ,
107110 } ) ;
108-
111+
109112 if ( DEV_MODE ) child . info ( { result } , '[Sprint Label Mutation]' ) ;
110113 }
111114 }
@@ -115,11 +118,11 @@ export const GITHUB_APP_WEBHOOKS = new Elysia({ prefix: "/webhooks" }).post(
115118 return ctx . body ;
116119 } ,
117120 {
118- detail : {
119- description :
120- "Receives a webhook event of the changes that happened in the scopes that this microservice is subscribed to, on your GitHub-App installation." ,
121- tags : [ "github" , "webhooks" ] ,
122- } ,
121+ detail : {
122+ description :
123+ "Receives a webhook event of the changes that happened in the scopes that this microservice is subscribed to, on your GitHub-App installation." ,
124+ tags : [ "github" , "webhooks" ] ,
125+ } ,
123126 } ,
124127) ;
125128
@@ -428,6 +431,65 @@ const ACCOUNT_LEVEL_CHILDREN = (login_type: "organization" | "user") =>
428431 } ,
429432 )
430433
434+ /**
435+ * Request project iteration issues
436+ */
437+ . get (
438+ "/iterations/issues" ,
439+ async ( { fetchParams, params : { login_name, project_id_or_name } , query, set } ) => {
440+ const response = await fetchGithubDataUsingGraphql < {
441+ organization ?: { projectV2 : ProjectV2 } ;
442+ user ?: { projectV2 : ProjectV2 } ;
443+ } > (
444+ AccountScopeEntryRoot (
445+ login_name ,
446+ getProjectIterationIssues (
447+ project_id_or_name ,
448+ query . pageSize ,
449+ query . continueAfter ,
450+ query . iterationFieldName ,
451+ ( query . scopes ?. split ( "," ) ?? [ ] ) as GITHUB_ITERATION_SCOPES [ ]
452+ ) ,
453+ login_type
454+ ) ,
455+ fetchParams . auth ,
456+ set ,
457+ fetchParams . auth_type ,
458+ ) ;
459+
460+ const user = FETCH_PROJECTS_FROM_ORGANIZATION ? "organization" : "user" ;
461+ if ( response ?. data && user in response . data && response . data [ user ] ?. projectV2 ) {
462+ const items = response . data [ user ] . projectV2 . items ;
463+ // Property 'state' does not exist on type 'DraftIssue | Issue | PullRequest'. -> This is not typed correctly...
464+ // @ts -ignore
465+ const openNodes = items ?. nodes ?. filter ( node => node ?. content ?. state === 'OPEN' ) ?? [ ] ;
466+ // @ts -ignore
467+ const closedNodes = items ?. nodes ?. filter ( node => node ?. content ?. state === 'CLOSED' ) ?? [ ] ;
468+
469+ response . data [ user ] . projectV2 . items = {
470+ totalCount : items . totalCount ,
471+ pageInfo : items . pageInfo ,
472+ open_issues : { nodes : openNodes } ,
473+ closed_issues : { nodes : closedNodes }
474+ } as any ;
475+ }
476+
477+ return response ;
478+ } ,
479+ {
480+ query : t . Object ( {
481+ pageSize : t . Optional ( t . Numeric ( { minimum : 1 , maximum : 100 } ) ) ,
482+ continueAfter : t . Optional ( t . String ( ) ) ,
483+ iterationFieldName : t . Optional ( t . String ( ) ) ,
484+ scopes : t . Optional ( t . String ( ) ) // t.Optional(t.Array(t.Enum(GITHUB_ITERATION_SCOPES)))
485+ } ) ,
486+ detail : {
487+ description : `Request project iteration issues for ${ login_type } . Scopes: ${ GITHUB_ITERATION_PARAMS } (/projects/{project_id}/iteration/issues?iteration_field_name=Sprint).` ,
488+ tags : [ "github" ] ,
489+ } ,
490+ } ,
491+ )
492+
431493 /**
432494 * Request repositories only in the account project. No infos.
433495 */
@@ -1476,7 +1538,7 @@ const ACCOUNT_LEVEL_CHILDREN = (login_type: "organization" | "user") =>
14761538 } ,
14771539 } ,
14781540 ) ,
1479- ) ,
1541+ ) ,
14801542 ) ,
14811543 ) ,
14821544 ) ,
0 commit comments