mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
feat(Github Trigger Node): Use resource locator component (#5253)
* ⚡️wip * ⚡️RLC Search Function for getUsers and getRepositories * 🐛fix Repository RLC by name url * 🐛 search method getRepositories include forks * 🐛 fix repository name can have a dot * 🐛 fix RLC extractValue without optional * 🎨 fix linting errors * 🎨 using prefix 'e.g.' in RLC placeholders --------- Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
87
packages/nodes-base/nodes/Github/SearchFunctions.ts
Normal file
87
packages/nodes-base/nodes/Github/SearchFunctions.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import type {
|
||||
ILoadOptionsFunctions,
|
||||
INodeListSearchItems,
|
||||
INodeListSearchResult,
|
||||
} from 'n8n-workflow';
|
||||
import { githubApiRequest } from './GenericFunctions';
|
||||
|
||||
type UserSearchItem = {
|
||||
login: string;
|
||||
html_url: string;
|
||||
};
|
||||
|
||||
type RepositorySearchItem = {
|
||||
name: string;
|
||||
html_url: string;
|
||||
};
|
||||
|
||||
type UserSearchResponse = {
|
||||
items: UserSearchItem[];
|
||||
total_count: number;
|
||||
};
|
||||
|
||||
type RepositorySearchResponse = {
|
||||
items: RepositorySearchItem[];
|
||||
total_count: number;
|
||||
};
|
||||
|
||||
export async function getUsers(
|
||||
this: ILoadOptionsFunctions,
|
||||
filter?: string,
|
||||
paginationToken?: string,
|
||||
): Promise<INodeListSearchResult> {
|
||||
const page = paginationToken ? +paginationToken : 1;
|
||||
const per_page = 100;
|
||||
const responseData: UserSearchResponse = await githubApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
'/search/users',
|
||||
{},
|
||||
{ q: filter, page, per_page },
|
||||
);
|
||||
|
||||
const results: INodeListSearchItems[] = responseData.items.map((item: UserSearchItem) => ({
|
||||
name: item.login,
|
||||
value: item.login,
|
||||
url: item.html_url,
|
||||
}));
|
||||
|
||||
const nextPaginationToken = page * per_page < responseData.total_count ? page + 1 : undefined;
|
||||
return { results, paginationToken: nextPaginationToken };
|
||||
}
|
||||
|
||||
export async function getRepositories(
|
||||
this: ILoadOptionsFunctions,
|
||||
filter?: string,
|
||||
paginationToken?: string,
|
||||
): Promise<INodeListSearchResult> {
|
||||
const owner = this.getCurrentNodeParameter('owner', { extractValue: true });
|
||||
const page = paginationToken ? +paginationToken : 1;
|
||||
const per_page = 100;
|
||||
const q = `${filter ?? ''} user:${owner} fork:true`;
|
||||
let responseData: RepositorySearchResponse = {
|
||||
items: [],
|
||||
total_count: 0,
|
||||
};
|
||||
|
||||
try {
|
||||
responseData = await githubApiRequest.call(
|
||||
this,
|
||||
'GET',
|
||||
'/search/repositories',
|
||||
{},
|
||||
{ q, page, per_page },
|
||||
);
|
||||
} catch (_error) {
|
||||
// will fail if the owner does not have any repositories
|
||||
}
|
||||
|
||||
const results: INodeListSearchItems[] = responseData.items.map((item: RepositorySearchItem) => ({
|
||||
name: item.name,
|
||||
value: item.name,
|
||||
url: item.html_url,
|
||||
}));
|
||||
|
||||
const nextPaginationToken = page * per_page < responseData.total_count ? page + 1 : undefined;
|
||||
return { results, paginationToken: nextPaginationToken };
|
||||
}
|
||||
Reference in New Issue
Block a user