-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gitea): add new pull requests trigger
- Loading branch information
1 parent
93fdc05
commit d45c8aa
Showing
3 changed files
with
127 additions
and
1 deletion.
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,5 +1,6 @@ | ||
import newIssues from './new-issues/index.js'; | ||
import newPullRequests from './new-pull-requests/index.js'; | ||
import newStargazers from './new-stargazers/index.js'; | ||
import newWatchers from './new-watchers/index.js'; | ||
|
||
export default [newIssues, newStargazers, newWatchers]; | ||
export default [newIssues, newPullRequests, newStargazers, newWatchers]; |
123 changes: 123 additions & 0 deletions
123
packages/backend/src/apps/gitea/triggers/new-pull-requests/index.js
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 |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import defineTrigger from '../../../../helpers/define-trigger.js'; | ||
|
||
export default defineTrigger({ | ||
name: 'New pull requests', | ||
key: 'newPullRequests', | ||
pollInterval: 15, | ||
description: 'Triggers when the user creates a new pull request.', | ||
arguments: [ | ||
{ | ||
label: 'Repo', | ||
key: 'repo', | ||
type: 'dropdown', | ||
required: true, | ||
variables: true, | ||
source: { | ||
type: 'query', | ||
name: 'getDynamicData', | ||
arguments: [ | ||
{ | ||
name: 'key', | ||
value: 'listRepos', | ||
}, | ||
], | ||
}, | ||
}, | ||
{ | ||
label: 'Which types of pulls should this trigger on?', | ||
key: 'pullType', | ||
type: 'dropdown', | ||
description: '', | ||
required: false, | ||
variables: true, | ||
value: 'all', | ||
options: [ | ||
{ | ||
label: 'Closed', | ||
value: 'closed', | ||
}, | ||
{ | ||
label: 'Open', | ||
value: 'open', | ||
}, | ||
{ | ||
label: 'All', | ||
value: 'all', | ||
}, | ||
], | ||
}, | ||
{ | ||
label: 'Type of Sort?', | ||
key: 'typeOfSort', | ||
type: 'dropdown', | ||
description: '', | ||
required: false, | ||
variables: true, | ||
value: 'all', | ||
options: [ | ||
{ | ||
label: 'Oldest', | ||
value: 'oldest', | ||
}, | ||
{ | ||
label: 'Recent Update', | ||
value: 'recentupdate', | ||
}, | ||
{ | ||
label: 'Least Update', | ||
value: 'leastupdate', | ||
}, | ||
{ | ||
label: 'Most Comment', | ||
value: 'mostcomment', | ||
}, | ||
{ | ||
label: 'Least Comment', | ||
value: 'leastcomment', | ||
}, | ||
{ | ||
label: 'Priority', | ||
value: 'priority', | ||
}, | ||
], | ||
}, | ||
], | ||
|
||
async run($) { | ||
const repo = $.step.parameters.repo; | ||
const typeOfSort = $.step.parameters.typeOfSort; | ||
const pullType = $.step.parameters.pullType; | ||
const repoOwner = $.auth.data.repoOwner; | ||
const params = { | ||
page: 1, | ||
limit: 100, | ||
sort: typeOfSort, | ||
state: pullType, | ||
}; | ||
|
||
let totalCount; | ||
let totalRequestedCount; | ||
do { | ||
const { data, headers } = await $.http.get( | ||
`/repos/${repoOwner}/${repo}/pulls`, | ||
{ | ||
params, | ||
} | ||
); | ||
params.page = params.page + 1; | ||
totalCount = Number(headers['x-total-count']); | ||
totalRequestedCount = params.page * params.limit; | ||
|
||
if (data?.length) { | ||
for (const pullRequest of data) { | ||
$.pushTriggerItem({ | ||
raw: pullRequest, | ||
meta: { | ||
internalId: pullRequest.id.toString(), | ||
}, | ||
}); | ||
} | ||
} | ||
} while (totalRequestedCount <= totalCount); | ||
}, | ||
}); |
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