fix(GitHub Node): Fix workflow resource locator (#13599)

This commit is contained in:
Shireen Missi 2025-03-03 14:09:38 +00:00 committed by GitHub
parent 850d458858
commit b7f7121cb8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 196 additions and 4 deletions

View file

@ -457,14 +457,12 @@ export class Github implements INodeType {
required: true, required: true,
modes: [ modes: [
{ {
displayName: 'Workflow', displayName: 'From List',
name: 'list', name: 'list',
type: 'list', type: 'list',
placeholder: 'Select a workflow...', placeholder: 'Select a workflow...',
typeOptions: { typeOptions: {
searchListMethod: 'getWorkflows', searchListMethod: 'getWorkflows',
searchable: true,
searchFilterRequired: true,
}, },
}, },
{ {
@ -482,6 +480,21 @@ export class Github implements INodeType {
}, },
], ],
}, },
{
displayName: 'By File Name',
name: 'filename',
type: 'string',
placeholder: 'e.g. main.yaml or main.yml',
validation: [
{
type: 'regex',
properties: {
regex: '[a-zA-Z0-9_-]+.(yaml|yml)',
errorMessage: 'Not a valid Github Workflow File Name',
},
},
],
},
], ],
displayOptions: { displayOptions: {
show: { show: {
@ -2501,7 +2514,9 @@ export class Github implements INodeType {
requestMethod = 'POST'; requestMethod = 'POST';
const workflowId = this.getNodeParameter('workflowId', i) as string; const workflowId = this.getNodeParameter('workflowId', i, undefined, {
extractValue: true,
}) as string;
endpoint = `/repos/${owner}/${repository}/actions/workflows/${workflowId}/dispatches`; endpoint = `/repos/${owner}/${repository}/actions/workflows/${workflowId}/dispatches`;
body.ref = this.getNodeParameter('ref', i) as string; body.ref = this.getNodeParameter('ref', i) as string;

View file

@ -0,0 +1,91 @@
import nock from 'nock';
import { getWorkflowFilenames, initBinaryDataService, testWorkflows } from '@test/nodes/Helpers';
const workflows = getWorkflowFilenames(__dirname);
describe('Test Github Node', () => {
describe('Workflow Dispatch', () => {
const now = 1683028800000;
const owner = 'testOwner';
const repository = 'testRepository';
const workflowId = 147025216;
const usersResponse = {
total_count: 12,
items: [
{
login: 'testOwner',
id: 1,
},
],
};
const repositoriesResponse = {
total_count: 40,
items: [
{
id: 3081286,
name: 'testRepository',
},
],
};
const workflowsResponse = {
total_count: 2,
workflows: [
{
id: workflowId,
node_id: 'MDg6V29ya2Zsb3cxNjEzMzU=',
name: 'CI',
path: '.github/workflows/blank.yaml',
state: 'active',
created_at: '2020-01-08T23:48:37.000-08:00',
updated_at: '2020-01-08T23:50:21.000-08:00',
url: 'https://api.github.com/repos/octo-org/octo-repo/actions/workflows/161335',
html_url: 'https://github.com/octo-org/octo-repo/blob/master/.github/workflows/161335',
badge_url: 'https://github.com/octo-org/octo-repo/workflows/CI/badge.svg',
},
{
id: 269289,
node_id: 'MDE4OldvcmtmbG93IFNlY29uZGFyeTI2OTI4OQ==',
name: 'Linter',
path: '.github/workflows/linter.yaml',
state: 'active',
created_at: '2020-01-08T23:48:37.000-08:00',
updated_at: '2020-01-08T23:50:21.000-08:00',
url: 'https://api.github.com/repos/octo-org/octo-repo/actions/workflows/269289',
html_url: 'https://github.com/octo-org/octo-repo/blob/master/.github/workflows/269289',
badge_url: 'https://github.com/octo-org/octo-repo/workflows/Linter/badge.svg',
},
],
};
beforeAll(async () => {
jest.useFakeTimers({ doNotFake: ['nextTick'], now });
await initBinaryDataService();
});
beforeEach(async () => {
const baseUrl = 'https://api.github.com';
nock.cleanAll();
nock(baseUrl)
.persist()
.defaultReplyHeaders({ 'Content-Type': 'application/json' })
.get('/search/users')
.query(true)
.reply(200, usersResponse)
.get('/search/repositories')
.query(true)
.reply(200, repositoriesResponse)
.get(`/repos/${owner}/${repository}/actions/workflows`)
.reply(200, workflowsResponse)
.post(`/repos/${owner}/${repository}/actions/workflows/${workflowId}/dispatches`, {
ref: 'main',
inputs: {},
})
.reply(200, {});
});
afterEach(() => {
nock.cleanAll();
});
testWorkflows(workflows);
});
});

View file

@ -0,0 +1,86 @@
{
"nodes": [
{
"parameters": {},
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [-300, 260],
"id": "b14bf20f-78b0-490a-bbc6-d02b1af4c03c",
"name": "When clicking Test workflow"
},
{
"parameters": {
"resource": "workflow",
"workflowId": {
"__rl": true,
"value": 147025216,
"mode": "list",
"cachedResultName": "CI"
},
"owner": {
"__rl": true,
"value": "testOwner",
"mode": "name"
},
"repository": {
"__rl": true,
"value": "testRepository",
"mode": "name"
}
},
"type": "n8n-nodes-base.github",
"typeVersion": 1,
"position": [-80, 260],
"id": "061752c9-507c-4b27-ba18-47b21d487aed",
"name": "GitHub",
"credentials": {
"githubApi": {
"id": "1",
"name": "GitHub account"
}
}
},
{
"parameters": {},
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [120, 260],
"id": "3bc54e8f-eeba-496d-a95f-bb8927eff671",
"name": "No Operation, do nothing"
}
],
"connections": {
"When clicking Test workflow": {
"main": [
[
{
"node": "GitHub",
"type": "main",
"index": 0
}
]
]
},
"GitHub": {
"main": [
[
{
"node": "No Operation, do nothing",
"type": "main",
"index": 0
}
]
]
}
},
"pinData": {
"No Operation, do nothing": [
{
"json": {}
}
]
},
"meta": {
"instanceId": "27cc9b56542ad45b38725555722c50a1c3fee1670bbb67980558314ee08517c4"
}
}