mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
feat(Github Node): Use resource locator component (#5489)
⚡️RLC for Repository Owner and Repository Name
This commit is contained in:
parent
6592d144d1
commit
00ac4c308a
|
@ -11,6 +11,7 @@ import { NodeOperationError } from 'n8n-workflow';
|
||||||
import { getFileSha, githubApiRequest, githubApiRequestAllItems } from './GenericFunctions';
|
import { getFileSha, githubApiRequest, githubApiRequestAllItems } from './GenericFunctions';
|
||||||
|
|
||||||
import { snakeCase } from 'change-case';
|
import { snakeCase } from 'change-case';
|
||||||
|
import { getRepositories, getUsers } from './SearchFunctions';
|
||||||
|
|
||||||
export class Github implements INodeType {
|
export class Github implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
|
@ -385,31 +386,122 @@ export class Github implements INodeType {
|
||||||
{
|
{
|
||||||
displayName: 'Repository Owner',
|
displayName: 'Repository Owner',
|
||||||
name: 'owner',
|
name: 'owner',
|
||||||
type: 'string',
|
type: 'resourceLocator',
|
||||||
default: '',
|
default: { mode: 'list', value: '' },
|
||||||
required: true,
|
required: true,
|
||||||
|
modes: [
|
||||||
|
{
|
||||||
|
displayName: 'Repository Owner',
|
||||||
|
name: 'list',
|
||||||
|
type: 'list',
|
||||||
|
placeholder: 'Select an owner...',
|
||||||
|
typeOptions: {
|
||||||
|
searchListMethod: 'getUsers',
|
||||||
|
searchable: true,
|
||||||
|
searchFilterRequired: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Link',
|
||||||
|
name: 'url',
|
||||||
|
type: 'string',
|
||||||
|
placeholder: 'e.g. https://github.com/n8n-io',
|
||||||
|
extractValue: {
|
||||||
|
type: 'regex',
|
||||||
|
regex: 'https:\\/\\/github.com\\/([-_0-9a-zA-Z]+)',
|
||||||
|
},
|
||||||
|
validation: [
|
||||||
|
{
|
||||||
|
type: 'regex',
|
||||||
|
properties: {
|
||||||
|
regex: 'https:\\/\\/github.com\\/([-_0-9a-zA-Z]+)(?:.*)',
|
||||||
|
errorMessage: 'Not a valid Github URL',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'By Name',
|
||||||
|
name: 'name',
|
||||||
|
type: 'string',
|
||||||
|
placeholder: 'e.g. n8n-io',
|
||||||
|
validation: [
|
||||||
|
{
|
||||||
|
type: 'regex',
|
||||||
|
properties: {
|
||||||
|
regex: '[-_a-zA-Z0-9]+',
|
||||||
|
errorMessage: 'Not a valid Github Owner Name',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
url: '=https://github.com/{{$value}}',
|
||||||
|
},
|
||||||
|
],
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
hide: {
|
hide: {
|
||||||
operation: ['invite'],
|
operation: ['invite'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
placeholder: 'n8n-io',
|
|
||||||
description: 'Owner of the repository',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Repository Name',
|
displayName: 'Repository Name',
|
||||||
name: 'repository',
|
name: 'repository',
|
||||||
type: 'string',
|
type: 'resourceLocator',
|
||||||
default: '',
|
default: { mode: 'list', value: '' },
|
||||||
required: true,
|
required: true,
|
||||||
|
modes: [
|
||||||
|
{
|
||||||
|
displayName: 'Repository Name',
|
||||||
|
name: 'list',
|
||||||
|
type: 'list',
|
||||||
|
placeholder: 'Select an Repository...',
|
||||||
|
typeOptions: {
|
||||||
|
searchListMethod: 'getRepositories',
|
||||||
|
searchable: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Link',
|
||||||
|
name: 'url',
|
||||||
|
type: 'string',
|
||||||
|
placeholder: 'e.g. https://github.com/n8n-io/n8n',
|
||||||
|
extractValue: {
|
||||||
|
type: 'regex',
|
||||||
|
regex: 'https:\\/\\/github.com\\/(?:[-_0-9a-zA-Z]+)\\/([-_.0-9a-zA-Z]+)',
|
||||||
|
},
|
||||||
|
validation: [
|
||||||
|
{
|
||||||
|
type: 'regex',
|
||||||
|
properties: {
|
||||||
|
regex: 'https:\\/\\/github.com\\/(?:[-_0-9a-zA-Z]+)\\/([-_.0-9a-zA-Z]+)(?:.*)',
|
||||||
|
errorMessage: 'Not a valid Github Repository URL',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'By Name',
|
||||||
|
name: 'name',
|
||||||
|
type: 'string',
|
||||||
|
placeholder: 'e.g. n8n',
|
||||||
|
validation: [
|
||||||
|
{
|
||||||
|
type: 'regex',
|
||||||
|
properties: {
|
||||||
|
regex: '[-_.0-9a-zA-Z]+',
|
||||||
|
errorMessage: 'Not a valid Github Repository Name',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
url: '=https://github.com/{{$parameter["owner"]}}/{{$value}}',
|
||||||
|
},
|
||||||
|
],
|
||||||
displayOptions: {
|
displayOptions: {
|
||||||
hide: {
|
hide: {
|
||||||
resource: ['user', 'organization'],
|
resource: ['user', 'organization'],
|
||||||
operation: ['getRepositories'],
|
operation: ['getRepositories'],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
placeholder: 'n8n',
|
|
||||||
description: 'The name of the repository',
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// ----------------------------------
|
// ----------------------------------
|
||||||
|
@ -1601,6 +1693,13 @@ export class Github implements INodeType {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
methods = {
|
||||||
|
listSearch: {
|
||||||
|
getUsers,
|
||||||
|
getRepositories,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
||||||
const items = this.getInputData();
|
const items = this.getInputData();
|
||||||
const returnData: INodeExecutionData[] = [];
|
const returnData: INodeExecutionData[] = [];
|
||||||
|
@ -1667,7 +1766,7 @@ export class Github implements INodeType {
|
||||||
let owner = '';
|
let owner = '';
|
||||||
if (fullOperation !== 'user:invite') {
|
if (fullOperation !== 'user:invite') {
|
||||||
// Request the parameters which almost all operations need
|
// Request the parameters which almost all operations need
|
||||||
owner = this.getNodeParameter('owner', i) as string;
|
owner = this.getNodeParameter('owner', i, '', { extractValue: true }) as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
let repository = '';
|
let repository = '';
|
||||||
|
@ -1676,7 +1775,7 @@ export class Github implements INodeType {
|
||||||
fullOperation !== 'user:invite' &&
|
fullOperation !== 'user:invite' &&
|
||||||
fullOperation !== 'organization:getRepositories'
|
fullOperation !== 'organization:getRepositories'
|
||||||
) {
|
) {
|
||||||
repository = this.getNodeParameter('repository', i) as string;
|
repository = this.getNodeParameter('repository', i, '', { extractValue: true }) as string;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resource === 'file') {
|
if (resource === 'file') {
|
||||||
|
|
Loading…
Reference in a new issue