diff --git a/src/components/Publications.js b/src/components/Publications.js index 27809fb9b..6c6d388a0 100644 --- a/src/components/Publications.js +++ b/src/components/Publications.js @@ -75,8 +75,8 @@ const Publications = ({ profile, repository, selectedBranch, hasWriteAccess }) = workflow.name.toLowerCase().includes('pages') ); - // Fetch recent workflow runs for each branch if ghbuild workflow exists - if (ghbuildWorkflow) { + // Fetch recent workflow runs for each branch if ghbuild workflow exists and has valid ID + if (ghbuildWorkflow && ghbuildWorkflow.id) { const runsByBranch = {}; for (const branch of filteredBranches) { try { @@ -94,6 +94,8 @@ const Publications = ({ profile, repository, selectedBranch, hasWriteAccess }) = } } setWorkflowRuns(runsByBranch); + } else if (ghbuildWorkflow && !ghbuildWorkflow.id) { + console.warn('Found workflow but missing ID:', ghbuildWorkflow); } setLoading(false); @@ -178,6 +180,12 @@ const Publications = ({ profile, repository, selectedBranch, hasWriteAccess }) = return; } + if (!ghbuildWorkflow.id) { + alert('Workflow found but missing ID - cannot restart'); + console.warn('Workflow missing ID:', ghbuildWorkflow); + return; + } + try { await githubService.triggerWorkflow(owner, repoName, ghbuildWorkflow.id, branchName); alert(`Workflow restarted for branch: ${branchName}`); diff --git a/src/services/githubService.js b/src/services/githubService.js index 60a8cc7d5..ef5ef0fbd 100644 --- a/src/services/githubService.js +++ b/src/services/githubService.js @@ -698,87 +698,34 @@ class GitHubService { // GitHub Actions API methods - // Get workflows for a repository (detailed version with file parsing) + // Get workflows for a repository (using GitHub API to include workflow IDs) async getWorkflows(owner, repo) { if (!this.isAuth()) { throw new Error('Not authenticated with GitHub'); } try { - // First, try to get the .github/workflows directory - const { data } = await this.octokit.rest.repos.getContent({ + // Use GitHub Actions API to get workflows with their IDs + const { data } = await this.octokit.rest.actions.listRepoWorkflows({ owner, - repo, - path: '.github/workflows' + repo }); - // Filter for YAML/YML files - const workflowFiles = Array.isArray(data) - ? data.filter(file => file.name.endsWith('.yml') || file.name.endsWith('.yaml')) - : []; - - // Fetch workflow details for each file - const workflows = await Promise.all( - workflowFiles.map(async (file) => { - try { - // Get file content to parse workflow name - const contentResponse = await this.octokit.rest.repos.getContent({ - owner, - repo, - path: file.path - }); - - const content = decodeURIComponent(escape(atob(contentResponse.data.content))); - - // Parse workflow name from YAML (simple regex approach) - const nameMatch = content.match(/^name:\s*(.+)$/m); - const workflowName = nameMatch ? nameMatch[1].replace(/['"]/g, '') : file.name.replace(/\.(yml|yaml)$/, ''); - - // Parse triggers - const onMatch = content.match(/^on:\s*$/m); - let triggers = []; - if (onMatch) { - const pushMatch = content.match(/^\s*push:/m); - const prMatch = content.match(/^\s*pull_request:/m); - const scheduleMatch = content.match(/^\s*schedule:/m); - const workflowDispatchMatch = content.match(/^\s*workflow_dispatch:/m); - - if (pushMatch) triggers.push('push'); - if (prMatch) triggers.push('pull_request'); - if (scheduleMatch) triggers.push('schedule'); - if (workflowDispatchMatch) triggers.push('manual'); - } - - return { - name: workflowName, - filename: file.name, - path: file.path, - size: file.size, - sha: file.sha, - url: file.html_url, - triggers: triggers.length > 0 ? triggers : ['push'], // default to push if we can't parse - lastModified: contentResponse.data.last_modified || 'Unknown' - }; - } catch (error) { - console.warn(`Failed to fetch workflow details for ${file.name}:`, error); - return { - name: file.name.replace(/\.(yml|yaml)$/, ''), - filename: file.name, - path: file.path, - size: file.size, - sha: file.sha, - url: file.html_url, - triggers: ['unknown'], - lastModified: 'Unknown' - }; - } - }) - ); - - return workflows; + return data.workflows.map(workflow => ({ + id: workflow.id, // This is the crucial missing piece! + name: workflow.name, + filename: workflow.path.split('/').pop(), // Extract filename from path + path: workflow.path, + state: workflow.state, + created_at: workflow.created_at, + updated_at: workflow.updated_at, + url: workflow.html_url, + triggers: ['unknown'], // GitHub API doesn't provide trigger info directly + lastModified: workflow.updated_at + })); } catch (error) { if (error.status === 404) { - // No .github/workflows directory exists + // No workflows or repository not found return []; } console.error('Failed to fetch workflows:', error);