Skip to content

Commit 38dffab

Browse files
author
Himanshu Singhal
committed
AIRA-64: Project Automation Action Update
1 parent 41edea6 commit 38dffab

File tree

1 file changed

+66
-9
lines changed

1 file changed

+66
-9
lines changed

.github/workflows/project-automation.yml

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,14 @@ jobs:
325325
return issues;
326326
}
327327
328-
// Helper function to find issue by AIRA number
328+
// Helper function to find issue by AIRA number (REST API fallback)
329329
async function findIssueByAiraNumber(airaNumber) {
330330
try {
331+
// First try GraphQL search
332+
console.log(` 🔍 Searching for AIRA-${airaNumber} using GraphQL...`);
333+
331334
const query = `
332-
query($owner: String!, $repo: String!, $searchQuery: String!) {
335+
query($searchQuery: String!) {
333336
search(query: $searchQuery, type: ISSUE, first: 10) {
334337
nodes {
335338
... on Issue {
@@ -344,11 +347,9 @@ jobs:
344347
`;
345348
346349
const searchQuery = `repo:${context.repo.owner}/${context.repo.repo} AIRA-${airaNumber} in:title`;
347-
console.log(` 🔍 Searching for: ${searchQuery}`);
350+
console.log(` 🔍 GraphQL search query: ${searchQuery}`);
348351
349352
const result = await github.graphql(query, {
350-
owner: context.repo.owner,
351-
repo: context.repo.repo,
352353
searchQuery
353354
});
354355
@@ -357,14 +358,70 @@ jobs:
357358
);
358359
359360
if (issues.length > 0) {
360-
console.log(` ✅ Found issue: #${issues[0].number} - ${issues[0].title}`);
361+
console.log(` ✅ Found issue via GraphQL: #${issues[0].number} - ${issues[0].title}`);
361362
return issues[0];
363+
}
364+
365+
console.log(` ❌ No results from GraphQL search, trying REST API...`);
366+
367+
} catch (graphqlError) {
368+
console.log(` ❌ GraphQL search failed: ${graphqlError.message}`);
369+
console.log(` 🔄 Falling back to REST API search...`);
370+
}
371+
372+
try {
373+
// Fallback to REST API search
374+
const searchResponse = await github.rest.search.issuesAndPullRequests({
375+
q: `repo:${context.repo.owner}/${context.repo.repo} AIRA-${airaNumber} in:title type:issue`,
376+
per_page: 10
377+
});
378+
379+
console.log(` 🔍 REST API found ${searchResponse.data.total_count} results`);
380+
381+
const matchingIssues = searchResponse.data.items.filter(issue =>
382+
issue.title.includes(`AIRA-${airaNumber}`)
383+
);
384+
385+
if (matchingIssues.length > 0) {
386+
const issue = matchingIssues[0];
387+
console.log(` ✅ Found issue via REST API: #${issue.number} - ${issue.title}`);
388+
return {
389+
number: issue.number,
390+
title: issue.title,
391+
state: issue.state,
392+
id: issue.node_id
393+
};
362394
} else {
363-
console.log(` ❌ No issue found for AIRA-${airaNumber}`);
395+
console.log(` ❌ No matching issues found for AIRA-${airaNumber}`);
364396
return null;
365397
}
366-
} catch (error) {
367-
console.log(` ❌ Error searching for AIRA-${airaNumber}:`, error.message);
398+
399+
} catch (restError) {
400+
console.log(` ❌ REST API search also failed: ${restError.message}`);
401+
402+
// Last resort: try to find by issue number if AIRA number matches
403+
try {
404+
console.log(` 🔄 Last resort: checking if AIRA-${airaNumber} corresponds to issue #${airaNumber}...`);
405+
406+
const issueResponse = await github.rest.issues.get({
407+
owner: context.repo.owner,
408+
repo: context.repo.repo,
409+
issue_number: airaNumber
410+
});
411+
412+
if (issueResponse.data.title.includes(`AIRA-${airaNumber}`)) {
413+
console.log(` ✅ Found by direct lookup: #${issueResponse.data.number} - ${issueResponse.data.title}`);
414+
return {
415+
number: issueResponse.data.number,
416+
title: issueResponse.data.title,
417+
state: issueResponse.data.state,
418+
id: issueResponse.data.node_id
419+
};
420+
}
421+
} catch (directError) {
422+
console.log(` ❌ Direct lookup failed: ${directError.message}`);
423+
}
424+
368425
return null;
369426
}
370427
}

0 commit comments

Comments
 (0)