Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
93fdc05529 | ||
![]() |
3e6f22748b |
102
packages/backend/src/apps/gitea/actions/create-issue/index.js
Normal file
102
packages/backend/src/apps/gitea/actions/create-issue/index.js
Normal file
@@ -0,0 +1,102 @@
|
||||
import defineAction from '../../../../helpers/define-action.js';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Create issue',
|
||||
key: 'createIssue',
|
||||
description: 'Creates a new issue.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Repo',
|
||||
key: 'repo',
|
||||
type: 'dropdown',
|
||||
required: true,
|
||||
variables: true,
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listRepos',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
label: 'Title',
|
||||
key: 'title',
|
||||
type: 'string',
|
||||
required: true,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Body',
|
||||
key: 'body',
|
||||
type: 'string',
|
||||
required: true,
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Labels',
|
||||
key: 'labels',
|
||||
type: 'dynamic',
|
||||
required: false,
|
||||
fields: [
|
||||
{
|
||||
label: 'Label',
|
||||
key: 'label',
|
||||
type: 'dropdown',
|
||||
description: 'Only trigger on issues when this label is added.',
|
||||
required: false,
|
||||
variables: true,
|
||||
dependsOn: ['parameters.repo'],
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listLabels',
|
||||
},
|
||||
{
|
||||
name: 'parameters.repo',
|
||||
value: '{parameters.repo}',
|
||||
},
|
||||
{
|
||||
name: 'parameters.showLabelId',
|
||||
value: 'true',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const repoOwner = $.auth.data.repoOwner;
|
||||
const repo = $.step.parameters.repo;
|
||||
const title = $.step.parameters.title;
|
||||
const issueBody = $.step.parameters.body;
|
||||
const allLabels = $.step.parameters.labels;
|
||||
const formattedAllLabels = allLabels
|
||||
.filter((label) => label.label !== '')
|
||||
.map((label) => label.label);
|
||||
|
||||
const body = {
|
||||
title,
|
||||
body: issueBody,
|
||||
};
|
||||
|
||||
if (formattedAllLabels.length) {
|
||||
body.labels = formattedAllLabels;
|
||||
}
|
||||
|
||||
const response = await $.http.post(
|
||||
`/repos/${repoOwner}/${repo}/issues`,
|
||||
body
|
||||
);
|
||||
|
||||
$.setActionItem({ raw: response.data });
|
||||
},
|
||||
});
|
3
packages/backend/src/apps/gitea/actions/index.js
Normal file
3
packages/backend/src/apps/gitea/actions/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
import createIssue from './create-issue/index.js';
|
||||
|
||||
export default [createIssue];
|
@@ -1,3 +1,4 @@
|
||||
import listLabels from './list-labels/index.js';
|
||||
import listRepos from './list-repos/index.js';
|
||||
|
||||
export default [listRepos];
|
||||
export default [listLabels, listRepos];
|
||||
|
@@ -0,0 +1,42 @@
|
||||
export default {
|
||||
name: 'List labels',
|
||||
key: 'listLabels',
|
||||
|
||||
async run($) {
|
||||
const labels = {
|
||||
data: [],
|
||||
};
|
||||
const repoOwner = $.auth.data.repoOwner;
|
||||
const repo = $.step.parameters.repo;
|
||||
const showLabelId = $.step.parameters.showLabelId === 'true';
|
||||
|
||||
const params = {
|
||||
page: 1,
|
||||
limit: 100,
|
||||
};
|
||||
|
||||
let totalCount;
|
||||
let totalRequestedCount;
|
||||
do {
|
||||
const { data, headers } = await $.http.get(
|
||||
`/repos/${repoOwner}/${repo}/labels`,
|
||||
{ params }
|
||||
);
|
||||
params.page = params.page + 1;
|
||||
totalCount = Number(headers['x-total-count']);
|
||||
totalRequestedCount = params.page * params.limit;
|
||||
|
||||
if (data?.length) {
|
||||
for (const label of data) {
|
||||
const value = showLabelId ? label.id : label.name;
|
||||
labels.data.push({
|
||||
value,
|
||||
name: label.name,
|
||||
});
|
||||
}
|
||||
}
|
||||
} while (totalRequestedCount <= totalCount);
|
||||
|
||||
return labels;
|
||||
},
|
||||
};
|
@@ -4,6 +4,7 @@ import auth from './auth/index.js';
|
||||
import setBaseUrl from './common/set-base-url.js';
|
||||
import triggers from './triggers/index.js';
|
||||
import dynamicData from './dynamic-data/index.js';
|
||||
import actions from './actions/index.js';
|
||||
|
||||
export default defineApp({
|
||||
name: 'Gitea',
|
||||
@@ -18,4 +19,5 @@ export default defineApp({
|
||||
auth,
|
||||
triggers,
|
||||
dynamicData,
|
||||
actions,
|
||||
});
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import newIssues from './new-issues/index.js';
|
||||
import newStargazers from './new-stargazers/index.js';
|
||||
import newWatchers from './new-watchers/index.js';
|
||||
|
||||
export default [newStargazers, newWatchers];
|
||||
export default [newIssues, newStargazers, newWatchers];
|
||||
|
121
packages/backend/src/apps/gitea/triggers/new-issues/index.js
Normal file
121
packages/backend/src/apps/gitea/triggers/new-issues/index.js
Normal file
@@ -0,0 +1,121 @@
|
||||
import defineTrigger from '../../../../helpers/define-trigger.js';
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New issues',
|
||||
key: 'newIssues',
|
||||
pollInterval: 15,
|
||||
description: 'Triggers when a new issue is created.',
|
||||
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 issues should this trigger on?',
|
||||
key: 'issueType',
|
||||
type: 'dropdown',
|
||||
description: 'Defaults to any issue you can see.',
|
||||
required: true,
|
||||
variables: true,
|
||||
value: 'all',
|
||||
options: [
|
||||
{
|
||||
label: 'Closed',
|
||||
value: 'closed',
|
||||
},
|
||||
{
|
||||
label: 'Open',
|
||||
value: 'open',
|
||||
},
|
||||
{
|
||||
label: 'All',
|
||||
value: 'all',
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Labels',
|
||||
key: 'labels',
|
||||
type: 'dynamic',
|
||||
required: false,
|
||||
fields: [
|
||||
{
|
||||
label: 'Label',
|
||||
key: 'label',
|
||||
type: 'dropdown',
|
||||
description: 'Only trigger on issues when this label is added.',
|
||||
required: false,
|
||||
variables: true,
|
||||
dependsOn: ['parameters.repo'],
|
||||
source: {
|
||||
type: 'query',
|
||||
name: 'getDynamicData',
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listLabels',
|
||||
},
|
||||
{
|
||||
name: 'parameters.repo',
|
||||
value: '{parameters.repo}',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const repo = $.step.parameters.repo;
|
||||
const issueType = $.step.parameters.issueType;
|
||||
const allLabels = $.step.parameters.labels;
|
||||
const formattedAllLabels = allLabels.map((label) => label.label).join(',');
|
||||
const repoOwner = $.auth.data.repoOwner;
|
||||
|
||||
const params = {
|
||||
page: 1,
|
||||
limit: 100,
|
||||
state: issueType,
|
||||
labels: formattedAllLabels,
|
||||
};
|
||||
|
||||
let totalCount;
|
||||
let totalRequestedCount;
|
||||
do {
|
||||
const { data, headers } = await $.http.get(
|
||||
`/repos/${repoOwner}/${repo}/issues`,
|
||||
{
|
||||
params,
|
||||
}
|
||||
);
|
||||
params.page = params.page + 1;
|
||||
totalCount = Number(headers['x-total-count']);
|
||||
totalRequestedCount = params.page * params.limit;
|
||||
|
||||
if (data?.length) {
|
||||
for (const issue of data) {
|
||||
$.pushTriggerItem({
|
||||
raw: issue,
|
||||
meta: {
|
||||
internalId: issue.id.toString(),
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
} while (totalRequestedCount <= totalCount);
|
||||
},
|
||||
});
|
@@ -128,6 +128,7 @@ export default defineConfig({
|
||||
collapsed: true,
|
||||
items: [
|
||||
{ text: 'Triggers', link: '/apps/gitea/triggers' },
|
||||
{ text: 'Actions', link: '/apps/gitea/actions' },
|
||||
{ text: 'Connection', link: '/apps/gitea/connection' },
|
||||
],
|
||||
},
|
||||
|
12
packages/docs/pages/apps/gitea/actions.md
Normal file
12
packages/docs/pages/apps/gitea/actions.md
Normal file
@@ -0,0 +1,12 @@
|
||||
---
|
||||
favicon: /favicons/gitea.svg
|
||||
items:
|
||||
- name: Create issue
|
||||
desc: Creates a new issue.
|
||||
---
|
||||
|
||||
<script setup>
|
||||
import CustomListing from '../../components/CustomListing.vue'
|
||||
</script>
|
||||
|
||||
<CustomListing />
|
@@ -1,6 +1,8 @@
|
||||
---
|
||||
favicon: /favicons/gitea.svg
|
||||
items:
|
||||
- name: New issues
|
||||
desc: Triggers when a new issue is created.
|
||||
- name: New stargazers
|
||||
desc: Triggers when a user stars a repository.
|
||||
- name: New watchers
|
||||
|
Reference in New Issue
Block a user