refactor: Use global output with github stargazers
This commit is contained in:
@@ -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($);
|
||||
},
|
||||
});
|
||||
|
@@ -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;
|
||||
|
@@ -9,7 +9,7 @@ export default defineTrigger({
|
||||
substeps: [
|
||||
{
|
||||
key: 'chooseConnection',
|
||||
name: 'Choose connection'
|
||||
name: 'Choose connection',
|
||||
},
|
||||
{
|
||||
key: 'chooseTrigger',
|
||||
@@ -27,20 +27,28 @@ export default defineTrigger({
|
||||
arguments: [
|
||||
{
|
||||
name: 'key',
|
||||
value: 'listRepos'
|
||||
}
|
||||
]
|
||||
}
|
||||
value: 'listRepos',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'testStep',
|
||||
name: 'Test trigger'
|
||||
}
|
||||
name: 'Test trigger',
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
return await newStargazers($);
|
||||
await newStargazers($);
|
||||
},
|
||||
|
||||
sort($) {
|
||||
$.triggerOutput.data.sort((stargazerA, stargazerB) => {
|
||||
return (
|
||||
Number(stargazerA.meta.internalId) - Number(stargazerB.meta.internalId)
|
||||
);
|
||||
});
|
||||
},
|
||||
});
|
||||
|
@@ -1,9 +1,5 @@
|
||||
import { DateTime } from 'luxon';
|
||||
import {
|
||||
IGlobalVariable,
|
||||
IJSONObject,
|
||||
ITriggerOutput,
|
||||
} from '@automatisch/types';
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
import getRepoOwnerAndRepo from '../../common/get-repo-owner-and-repo';
|
||||
import parseLinkHeader from '../../../../helpers/parse-header-link';
|
||||
|
||||
@@ -12,7 +8,7 @@ type TResponseDataItem = {
|
||||
user: IJSONObject;
|
||||
};
|
||||
|
||||
const fetchStargazers = async ($: IGlobalVariable) => {
|
||||
const newStargazers = async ($: IGlobalVariable) => {
|
||||
const { repoOwner, repo } = getRepoOwnerAndRepo(
|
||||
$.step.parameters.repo as string
|
||||
);
|
||||
@@ -36,10 +32,6 @@ const fetchStargazers = async ($: IGlobalVariable) => {
|
||||
// in case there is only single page to fetch
|
||||
let pathname = firstPageLinks.last?.uri || firstPagePathname;
|
||||
|
||||
const stargazers: ITriggerOutput = {
|
||||
data: [],
|
||||
};
|
||||
|
||||
do {
|
||||
const response = await $.http.get<TResponseDataItem[]>(
|
||||
pathname,
|
||||
@@ -48,18 +40,13 @@ const fetchStargazers = async ($: IGlobalVariable) => {
|
||||
const links = parseLinkHeader(response.headers.link);
|
||||
pathname = links.prev?.uri;
|
||||
|
||||
if (response.httpError) {
|
||||
stargazers.error = response.httpError;
|
||||
return stargazers;
|
||||
}
|
||||
|
||||
if (response.data.length) {
|
||||
for (const starEntry of response.data) {
|
||||
const { starred_at, user } = starEntry;
|
||||
const timestamp = DateTime.fromISO(starred_at).toMillis();
|
||||
|
||||
if (timestamp <= Number($.flow.lastInternalId) && !$.execution.testRun)
|
||||
return stargazers;
|
||||
return;
|
||||
|
||||
const dataItem = {
|
||||
raw: user,
|
||||
@@ -68,24 +55,10 @@ const fetchStargazers = async ($: IGlobalVariable) => {
|
||||
},
|
||||
};
|
||||
|
||||
stargazers.data.push(dataItem);
|
||||
$.triggerOutput.data.push(dataItem);
|
||||
}
|
||||
}
|
||||
} while (pathname && !$.execution.testRun);
|
||||
|
||||
return stargazers;
|
||||
};
|
||||
|
||||
const newStargazers = async ($: IGlobalVariable) => {
|
||||
const stargazers = await fetchStargazers($);
|
||||
|
||||
stargazers.data.sort((stargazerA, stargazerB) => {
|
||||
return (
|
||||
Number(stargazerA.meta.internalId) - Number(stargazerB.meta.internalId)
|
||||
);
|
||||
});
|
||||
|
||||
return stargazers;
|
||||
};
|
||||
|
||||
export default newStargazers;
|
||||
|
Reference in New Issue
Block a user