Skip to content

Commit

Permalink
chore: remove dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
dessant committed Jul 4, 2021
1 parent 877b357 commit 143df30
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 29 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
22 changes: 9 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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) {
Expand All @@ -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 = [];

Expand Down Expand Up @@ -85,19 +84,19 @@ 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}"`)
.join(' ');
query += ` ${queryPart}`;
}

const excludeCreatedBefore = this.config[type + 'ExcludeCreatedBefore'];
const excludeCreatedBefore = this.config[`${type}-exclude-created-before`];
if (excludeCreatedBefore) {
query += ` created:>${this.getISOTimestamp(excludeCreatedBefore)}`;
}
Expand Down Expand Up @@ -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});
Expand Down
28 changes: 14 additions & 14 deletions src/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -56,7 +56,7 @@ const schema = Joi.object({
)
.default(''),

issueExcludeLabels: Joi.alternatives()
'issue-exclude-labels': Joi.alternatives()
.try(
extendedJoi
.stringList()
Expand All @@ -74,7 +74,7 @@ const schema = Joi.object({
)
.default(''),

issueLockLabels: Joi.alternatives()
'issue-lock-labels': Joi.alternatives()
.try(
extendedJoi
.stringList()
Expand All @@ -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()
Expand All @@ -120,7 +120,7 @@ const schema = Joi.object({
)
.default(''),

prExcludeLabels: Joi.alternatives()
'pr-exclude-labels': Joi.alternatives()
.try(
extendedJoi
.stringList()
Expand All @@ -138,7 +138,7 @@ const schema = Joi.object({
)
.default(''),

prLockLabels: Joi.alternatives()
'pr-lock-labels': Joi.alternatives()
.try(
extendedJoi
.stringList()
Expand All @@ -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('')
Expand Down

0 comments on commit 143df30

Please sign in to comment.