refactor: Use global output with github stargazers

This commit is contained in:
Faruk AYDIN
2022-10-21 19:30:33 +02:00
parent 0f63f6d453
commit 59b9c66a91
4 changed files with 46 additions and 76 deletions

View File

@@ -9,7 +9,7 @@ export default defineTrigger({
substeps: [
{
key: 'chooseConnection',
name: 'Choose connection'
name: 'Choose connection',
},
{
key: 'chooseTrigger',
@@ -27,10 +27,10 @@ export default defineTrigger({
arguments: [
{
name: 'key',
value: 'listRepos'
}
]
}
value: 'listRepos',
},
],
},
},
{
label: 'Which types of issues should this trigger on?',
@@ -43,25 +43,25 @@ export default defineTrigger({
options: [
{
label: 'Any issue you can see',
value: 'all'
value: 'all',
},
{
label: 'Only issues assigned to you',
value: 'assigned'
value: 'assigned',
},
{
label: 'Only issues created by you',
value: 'created'
value: 'created',
},
{
label: `Only issues you're mentioned in`,
value: 'mentioned'
value: 'mentioned',
},
{
label: `Only issues you're subscribed to`,
value: 'subscribed'
}
]
value: 'subscribed',
},
],
},
{
label: 'Label',
@@ -77,24 +77,24 @@ export default defineTrigger({
arguments: [
{
name: 'key',
value: 'listLabels'
value: 'listLabels',
},
{
name: 'parameters.repo',
value: '{parameters.repo}'
}
]
}
}
]
value: '{parameters.repo}',
},
],
},
},
],
},
{
key: 'testStep',
name: 'Test trigger'
}
name: 'Test trigger',
},
],
async run($) {
return await newIssues($);
await newIssues($);
},
});

View File

@@ -1,4 +1,4 @@
import { IGlobalVariable, ITriggerOutput } from '@automatisch/types';
import { IGlobalVariable } from '@automatisch/types';
import getRepoOwnerAndRepo from '../../common/get-repo-owner-and-repo';
import parseLinkHeader from '../../../../helpers/parse-header-link';
@@ -25,26 +25,17 @@ const newIssues = async ($: IGlobalVariable) => {
per_page: 100,
};
const issues: ITriggerOutput = {
data: [],
};
let links;
do {
const response = await $.http.get(pathname, { params });
links = parseLinkHeader(response.headers.link);
if (response.httpError) {
issues.error = response.httpError;
return issues;
}
if (response.data.length) {
for (const issue of response.data) {
const issueId = issue.id;
if (issueId <= Number($.flow.lastInternalId) && !$.execution.testRun)
return issues;
return;
const dataItem = {
raw: issue,
@@ -53,12 +44,10 @@ const newIssues = async ($: IGlobalVariable) => {
},
};
issues.data.push(dataItem);
$.triggerOutput.data.push(dataItem);
}
}
} while (links.next && !$.execution.testRun);
return issues;
};
export default newIssues;