Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gitea): add new pull requests trigger #1854

Open
wants to merge 1 commit into
base: AUT-960
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/backend/src/apps/gitea/triggers/index.js
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 packages/backend/src/apps/gitea/triggers/new-pull-requests/index.js
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);
},
});
2 changes: 2 additions & 0 deletions packages/docs/pages/apps/gitea/triggers.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ favicon: /favicons/gitea.svg
items:
- name: New issues
desc: Triggers when a new issue is created.
- name: New pull requests
desc: Triggers when the user creates a new pull request.
- name: New stargazers
desc: Triggers when a user stars a repository.
- name: New watchers
Expand Down
Loading