chore: remove dependency

This commit is contained in:
dessant
2021-07-04 16:56:52 +03:00
parent 877b357328
commit 143df30520
3 changed files with 24 additions and 29 deletions

View File

@@ -22,8 +22,7 @@
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/github": "^4.0.0",
"joi": "^17.3.0",
"decamelize": "^4.0.0"
"joi": "^17.3.0"
},
"devDependencies": {
"@vercel/ncc": "^0.26.1",

View File

@@ -1,13 +1,12 @@
const core = require('@actions/core');
const github = require('@actions/github');
const decamelize = require('decamelize');
const schema = require('./schema');
async function run() {
try {
const config = getConfig();
const client = github.getOctokit(config.githubToken);
const client = github.getOctokit(config['github-token']);
const app = new App(config, client);
await app.lockThreads();
@@ -23,7 +22,7 @@ class App {
}
async lockThreads() {
const type = this.config.processOnly;
const type = this.config['process-only'];
const threadTypes = type ? [type] : ['issue', 'pr'];
for (const item of threadTypes) {
@@ -35,9 +34,9 @@ class App {
async lock(type) {
const repo = github.context.repo;
const lockLabels = this.config[type + 'LockLabels'];
const lockComment = this.config[type + 'LockComment'];
const lockReason = this.config[type + 'LockReason'];
const lockLabels = this.config[`${type}-lock-labels`];
const lockComment = this.config[`${type}-lock-comment`];
const lockReason = this.config[`${type}-lock-reason`];
const threads = [];
@@ -85,11 +84,11 @@ class App {
async search(type) {
const {owner, repo} = github.context.repo;
const timestamp = this.getUpdatedTimestamp(
this.config[type + 'LockInactiveDays']
this.config[`${type}-lock-inactive-days`]
);
let query = `repo:${owner}/${repo} updated:<${timestamp} is:closed is:unlocked`;
const excludeLabels = this.config[type + 'ExcludeLabels'];
const excludeLabels = this.config[`${type}-exclude-labels`];
if (excludeLabels) {
const queryPart = excludeLabels
.map(label => `-label:"${label}"`)
@@ -97,7 +96,7 @@ class App {
query += ` ${queryPart}`;
}
const excludeCreatedBefore = this.config[type + 'ExcludeCreatedBefore'];
const excludeCreatedBefore = this.config[`${type}-exclude-created-before`];
if (excludeCreatedBefore) {
query += ` created:>${this.getISOTimestamp(excludeCreatedBefore)}`;
}
@@ -135,10 +134,7 @@ class App {
function getConfig() {
const input = Object.fromEntries(
Object.keys(schema.describe().keys).map(item => [
item,
core.getInput(decamelize(item, '-'))
])
Object.keys(schema.describe().keys).map(item => [item, core.getInput(item)])
);
const {error, value} = schema.validate(input, {abortEarly: false});

View File

@@ -34,17 +34,17 @@ const extendedJoi = Joi.extend({
});
const schema = Joi.object({
githubToken: Joi.string()
'github-token': Joi.string()
.trim()
.max(100),
issueLockInactiveDays: Joi.number()
'issue-lock-inactive-days': Joi.number()
.min(0)
.max(3650)
.precision(9)
.default(365),
issueExcludeCreatedBefore: Joi.alternatives()
'issue-exclude-created-before': Joi.alternatives()
.try(
Joi.date()
// .iso()
@@ -56,7 +56,7 @@ const schema = Joi.object({
)
.default(''),
issueExcludeLabels: Joi.alternatives()
'issue-exclude-labels': Joi.alternatives()
.try(
extendedJoi
.stringList()
@@ -74,7 +74,7 @@ const schema = Joi.object({
)
.default(''),
issueLockLabels: Joi.alternatives()
'issue-lock-labels': Joi.alternatives()
.try(
extendedJoi
.stringList()
@@ -92,23 +92,23 @@ const schema = Joi.object({
)
.default(''),
issueLockComment: Joi.string()
'issue-lock-comment': Joi.string()
.trim()
.max(10000)
.allow('')
.default(''),
issueLockReason: Joi.string()
'issue-lock-reason': Joi.string()
.valid('resolved', 'off-topic', 'too heated', 'spam', '')
.default('resolved'),
prLockInactiveDays: Joi.number()
'pr-lock-inactive-days': Joi.number()
.min(0)
.max(3650)
.precision(9)
.default(365),
prExcludeCreatedBefore: Joi.alternatives()
'pr-exclude-created-before': Joi.alternatives()
.try(
Joi.date()
// .iso()
@@ -120,7 +120,7 @@ const schema = Joi.object({
)
.default(''),
prExcludeLabels: Joi.alternatives()
'pr-exclude-labels': Joi.alternatives()
.try(
extendedJoi
.stringList()
@@ -138,7 +138,7 @@ const schema = Joi.object({
)
.default(''),
prLockLabels: Joi.alternatives()
'pr-lock-labels': Joi.alternatives()
.try(
extendedJoi
.stringList()
@@ -156,17 +156,17 @@ const schema = Joi.object({
)
.default(''),
prLockComment: Joi.string()
'pr-lock-comment': Joi.string()
.trim()
.max(10000)
.allow('')
.default(''),
prLockReason: Joi.string()
'pr-lock-reason': Joi.string()
.valid('resolved', 'off-topic', 'too heated', 'spam', '')
.default('resolved'),
processOnly: extendedJoi
'process-only': extendedJoi
.processOnly()
.valid('issue', 'pr', '')
.default('')