1- import Base from '../../../../../src/core/Base.mjs' ;
1+ import Base from '../../../../../src/core/Base.mjs' ;
22import GraphqlService from './GraphqlService.mjs' ;
3- import aiConfig from '../config.mjs' ;
4- import logger from '../logger.mjs' ;
3+ import aiConfig from '../config.mjs' ;
4+ import logger from '../logger.mjs' ;
5+ import { GET_ISSUE_AND_LABEL_IDS } from './queries/issueQueries.mjs' ;
6+ import { ADD_LABELS , REMOVE_LABELS } from './queries/mutations.mjs' ;
57
68/**
79 * Service for interacting with GitHub issues via the GraphQL API.
@@ -31,29 +33,14 @@ class IssueService extends Base {
3133 * @private
3234 */
3335 async #getIds( issueNumber , labelNames ) {
34- const query = `
35- query GetIds($owner: String!, $repo: String!, $issueNumber: Int!) {
36- repository(owner: $owner, name: $repo) {
37- issue(number: $issueNumber) {
38- id
39- }
40- labels(first: 100) { # Assuming max 100 labels
41- nodes {
42- id
43- name
44- }
45- }
46- }
47- }
48- ` ;
49-
5036 const variables = {
51- owner : aiConfig . owner ,
52- repo : aiConfig . repo ,
53- issueNumber
37+ owner : aiConfig . owner ,
38+ repo : aiConfig . repo ,
39+ issueNumber,
40+ maxLabels : aiConfig . issueSync . maxRepoLabels
5441 } ;
5542
56- const data = await GraphqlService . query ( query , variables ) ;
43+ const data = await GraphqlService . query ( GET_ISSUE_AND_LABEL_IDS , variables ) ;
5744
5845 const labelableId = data . repository . issue . id ;
5946 const repoLabels = data . repository . labels . nodes ;
@@ -79,15 +66,7 @@ class IssueService extends Base {
7966 try {
8067 const { labelableId, labelIds } = await this . #getIds( issueNumber , labels ) ;
8168
82- const mutation = `
83- mutation AddLabels($labelableId: ID!, $labelIds: [ID!]!) {
84- addLabelsToLabelable(input: {labelableId: $labelableId, labelIds: $labelIds}) {
85- clientMutationId
86- }
87- }
88- ` ;
89-
90- await GraphqlService . query ( mutation , { labelableId, labelIds } ) ;
69+ await GraphqlService . query ( ADD_LABELS , { labelableId, labelIds } ) ;
9170 return { message : `Successfully added labels to issue #${ issueNumber } ` } ;
9271 } catch ( error ) {
9372 logger . error ( `Error adding labels to issue #${ issueNumber } via GraphQL:` , error ) ;
@@ -109,15 +88,7 @@ class IssueService extends Base {
10988 try {
11089 const { labelableId, labelIds } = await this . #getIds( issueNumber , labels ) ;
11190
112- const mutation = `
113- mutation RemoveLabels($labelableId: ID!, $labelIds: [ID!]!) {
114- removeLabelsFromLabelable(input: {labelableId: $labelableId, labelIds: $labelIds}) {
115- clientMutationId
116- }
117- }
118- ` ;
119-
120- await GraphqlService . query ( mutation , { labelableId, labelIds } ) ;
91+ await GraphqlService . query ( REMOVE_LABELS , { labelableId, labelIds } ) ;
12192 return { message : `Successfully removed labels from issue #${ issueNumber } ` } ;
12293 } catch ( error ) {
12394 logger . error ( `Error removing labels from issue #${ issueNumber } via GraphQL:` , error ) ;
0 commit comments