Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4644 from kishanprmr/github-repo-dropdown
fix(github): load more than 100 repo
- Loading branch information
Showing
2 changed files
with
157 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"name": "@activepieces/piece-github", | ||
"version": "0.3.9" | ||
"version": "0.3.10" | ||
} |
302 changes: 156 additions & 146 deletions
302
packages/pieces/community/github/src/lib/common/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,170 +1,180 @@ | ||
import { Property, OAuth2PropertyValue } from '@activepieces/pieces-framework'; | ||
import { | ||
HttpRequest, | ||
HttpMethod, | ||
AuthenticationType, | ||
httpClient, | ||
HttpRequest, | ||
HttpMethod, | ||
AuthenticationType, | ||
httpClient, | ||
} from '@activepieces/pieces-common'; | ||
|
||
export const githubCommon = { | ||
baseUrl: 'https://api.github.com', | ||
repositoryDropdown: Property.Dropdown<{ repo: string; owner: string }>({ | ||
displayName: 'Repository', | ||
refreshers: [], | ||
required: true, | ||
options: async ({ auth }) => { | ||
if (!auth) { | ||
return { | ||
disabled: true, | ||
options: [], | ||
placeholder: 'please authenticate first', | ||
}; | ||
} | ||
const authProp: OAuth2PropertyValue = auth as OAuth2PropertyValue; | ||
const repositories = await getUserRepo(authProp); | ||
return { | ||
disabled: false, | ||
options: repositories.map((repo) => { | ||
return { | ||
label: repo.owner.login + '/' + repo.name, | ||
value: { | ||
owner: repo.owner.login, | ||
repo: repo.name, | ||
}, | ||
}; | ||
}), | ||
}; | ||
}, | ||
}), | ||
assigneeDropDown: (required = false) => | ||
Property.MultiSelectDropdown({ | ||
displayName: 'Assignees', | ||
description: 'Assignees for the Issue', | ||
refreshers: ['repository'], | ||
baseUrl: 'https://api.github.com', | ||
repositoryDropdown: Property.Dropdown<{ repo: string; owner: string }>({ | ||
displayName: 'Repository', | ||
refreshers: [], | ||
required: true, | ||
options: async ({ auth }) => { | ||
if (!auth) { | ||
return { | ||
disabled: true, | ||
options: [], | ||
placeholder: 'please authenticate first', | ||
}; | ||
} | ||
const authProp: OAuth2PropertyValue = auth as OAuth2PropertyValue; | ||
const repositories = await getUserRepo(authProp); | ||
return { | ||
disabled: false, | ||
options: repositories.map((repo) => { | ||
return { | ||
label: repo.owner.login + '/' + repo.name, | ||
value: { | ||
owner: repo.owner.login, | ||
repo: repo.name, | ||
}, | ||
}; | ||
}), | ||
}; | ||
}, | ||
}), | ||
assigneeDropDown: (required = false) => | ||
Property.MultiSelectDropdown({ | ||
displayName: 'Assignees', | ||
description: 'Assignees for the Issue', | ||
refreshers: ['repository'], | ||
|
||
required, | ||
options: async ({ auth, repository }) => { | ||
if (!auth || !repository) { | ||
return { | ||
disabled: true, | ||
options: [], | ||
placeholder: 'please authenticate first and select repo', | ||
}; | ||
} | ||
const authProp: OAuth2PropertyValue = auth as OAuth2PropertyValue; | ||
const { owner, repo } = repository as RepositoryProp; | ||
const assignees = await getAssignee(authProp, owner, repo); | ||
return { | ||
disabled: false, | ||
options: assignees.map((assignee) => { | ||
return { | ||
label: assignee.login, | ||
value: assignee.login, | ||
}; | ||
}), | ||
}; | ||
}, | ||
}), | ||
labelDropDown: (required = false) => | ||
Property.MultiSelectDropdown({ | ||
displayName: 'Labels', | ||
description: 'Labels for the Issue', | ||
refreshers: ['repository'], | ||
required, | ||
options: async ({ auth, repository }) => { | ||
if (!auth || !repository) { | ||
return { | ||
disabled: true, | ||
options: [], | ||
placeholder: 'please authenticate first and select repo', | ||
}; | ||
} | ||
const authProp: OAuth2PropertyValue = auth as OAuth2PropertyValue; | ||
const { owner, repo } = repository as RepositoryProp; | ||
const labels = await listIssueLabels(authProp, owner, repo); | ||
return { | ||
disabled: false, | ||
options: labels.map((label) => { | ||
return { | ||
label: label.name, | ||
value: label.name, | ||
}; | ||
}), | ||
}; | ||
}, | ||
}), | ||
required, | ||
options: async ({ auth, repository }) => { | ||
if (!auth || !repository) { | ||
return { | ||
disabled: true, | ||
options: [], | ||
placeholder: 'please authenticate first and select repo', | ||
}; | ||
} | ||
const authProp: OAuth2PropertyValue = auth as OAuth2PropertyValue; | ||
const { owner, repo } = repository as RepositoryProp; | ||
const assignees = await getAssignee(authProp, owner, repo); | ||
return { | ||
disabled: false, | ||
options: assignees.map((assignee) => { | ||
return { | ||
label: assignee.login, | ||
value: assignee.login, | ||
}; | ||
}), | ||
}; | ||
}, | ||
}), | ||
labelDropDown: (required = false) => | ||
Property.MultiSelectDropdown({ | ||
displayName: 'Labels', | ||
description: 'Labels for the Issue', | ||
refreshers: ['repository'], | ||
required, | ||
options: async ({ auth, repository }) => { | ||
if (!auth || !repository) { | ||
return { | ||
disabled: true, | ||
options: [], | ||
placeholder: 'please authenticate first and select repo', | ||
}; | ||
} | ||
const authProp: OAuth2PropertyValue = auth as OAuth2PropertyValue; | ||
const { owner, repo } = repository as RepositoryProp; | ||
const labels = await listIssueLabels(authProp, owner, repo); | ||
return { | ||
disabled: false, | ||
options: labels.map((label) => { | ||
return { | ||
label: label.name, | ||
value: label.name, | ||
}; | ||
}), | ||
}; | ||
}, | ||
}), | ||
}; | ||
|
||
async function getUserRepo( | ||
authProp: OAuth2PropertyValue | ||
): Promise<GithubRepository[]> { | ||
const request: HttpRequest = { | ||
method: HttpMethod.GET, | ||
url: `${githubCommon.baseUrl}/user/repos`, | ||
queryParams: { | ||
per_page: '200', | ||
}, | ||
authentication: { | ||
type: AuthenticationType.BEARER_TOKEN, | ||
token: authProp.access_token, | ||
}, | ||
}; | ||
const response = await httpClient.sendRequest<GithubRepository[]>(request); | ||
return response.body; | ||
async function getUserRepo(authProp: OAuth2PropertyValue): Promise<GithubRepository[]> { | ||
let page = 1; | ||
let hasNext; | ||
const repos: GithubRepository[] = []; | ||
do { | ||
const request: HttpRequest = { | ||
method: HttpMethod.GET, | ||
url: `${githubCommon.baseUrl}/user/repos`, | ||
queryParams: { | ||
page: page.toString(), | ||
per_page: '100', | ||
}, | ||
authentication: { | ||
type: AuthenticationType.BEARER_TOKEN, | ||
token: authProp.access_token, | ||
}, | ||
}; | ||
|
||
const response = await httpClient.sendRequest<GithubRepository[]>(request); | ||
repos.push(...response.body); | ||
|
||
hasNext = response.headers?.link?.includes('rel="next"'); | ||
page += 1; | ||
} while (hasNext); | ||
|
||
return repos; | ||
} | ||
async function getAssignee( | ||
authProp: OAuth2PropertyValue, | ||
owner: string, | ||
repo: string | ||
authProp: OAuth2PropertyValue, | ||
owner: string, | ||
repo: string, | ||
): Promise<GithubAssignee[]> { | ||
const request: HttpRequest = { | ||
method: HttpMethod.GET, | ||
url: `${githubCommon.baseUrl}/repos/${owner}/${repo}/assignees`, | ||
queryParams: { | ||
per_page: '30', | ||
}, | ||
authentication: { | ||
type: AuthenticationType.BEARER_TOKEN, | ||
token: authProp.access_token, | ||
}, | ||
}; | ||
const response = await httpClient.sendRequest<GithubAssignee[]>(request); | ||
return response.body; | ||
const request: HttpRequest = { | ||
method: HttpMethod.GET, | ||
url: `${githubCommon.baseUrl}/repos/${owner}/${repo}/assignees`, | ||
queryParams: { | ||
per_page: '30', | ||
}, | ||
authentication: { | ||
type: AuthenticationType.BEARER_TOKEN, | ||
token: authProp.access_token, | ||
}, | ||
}; | ||
const response = await httpClient.sendRequest<GithubAssignee[]>(request); | ||
return response.body; | ||
} | ||
|
||
async function listIssueLabels( | ||
authProp: OAuth2PropertyValue, | ||
owner: string, | ||
repo: string | ||
authProp: OAuth2PropertyValue, | ||
owner: string, | ||
repo: string, | ||
): Promise<GithubIssueLabel[]> { | ||
const request: HttpRequest = { | ||
method: HttpMethod.GET, | ||
url: `${githubCommon.baseUrl}/repos/${owner}/${repo}/labels`, | ||
queryParams: { | ||
per_page: '30', | ||
}, | ||
authentication: { | ||
type: AuthenticationType.BEARER_TOKEN, | ||
token: authProp.access_token, | ||
}, | ||
}; | ||
const response = await httpClient.sendRequest<GithubIssueLabel[]>(request); | ||
return response.body; | ||
const request: HttpRequest = { | ||
method: HttpMethod.GET, | ||
url: `${githubCommon.baseUrl}/repos/${owner}/${repo}/labels`, | ||
queryParams: { | ||
per_page: '30', | ||
}, | ||
authentication: { | ||
type: AuthenticationType.BEARER_TOKEN, | ||
token: authProp.access_token, | ||
}, | ||
}; | ||
const response = await httpClient.sendRequest<GithubIssueLabel[]>(request); | ||
return response.body; | ||
} | ||
export interface GithubRepository { | ||
name: string; | ||
owner: { | ||
login: string; | ||
}; | ||
name: string; | ||
owner: { | ||
login: string; | ||
}; | ||
} | ||
export interface GithubAssignee { | ||
login: string; | ||
login: string; | ||
} | ||
export interface GithubIssueLabel { | ||
id: string; | ||
name: string; | ||
id: string; | ||
name: string; | ||
} | ||
export interface RepositoryProp { | ||
repo: string; | ||
owner: string; | ||
repo: string; | ||
owner: string; | ||
} |