mirror of
https://github.com/dessant/lock-threads.git
synced 2026-03-13 01:27:03 -04:00
chore: populate repository
This commit is contained in:
9
.env.example
Normal file
9
.env.example
Normal file
@@ -0,0 +1,9 @@
|
||||
# The ID of your GitHub App
|
||||
APP_ID=
|
||||
WEBHOOK_SECRET=development
|
||||
|
||||
# Uncomment this to get verbose logging
|
||||
# LOG_LEVEL=trace # or `info` to show less
|
||||
|
||||
# Subdomain to use for localtunnel server. Defaults to your local username.
|
||||
# SUBDOMAIN=
|
||||
11
.gitignore
vendored
Normal file
11
.gitignore
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
.assets/
|
||||
.data/
|
||||
.env
|
||||
*.pem
|
||||
|
||||
node_modules/
|
||||
|
||||
npm-debug.log
|
||||
yarn-debug.log
|
||||
yarn-error.log
|
||||
.yarn-integrity
|
||||
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Armin Sebastian
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
69
README.md
Normal file
69
README.md
Normal file
@@ -0,0 +1,69 @@
|
||||
# Lock Threads
|
||||
|
||||
Lock Threads is a GitHub App inspired by [Stale](https://github.com/probot/stale)
|
||||
and built with [Probot](https://github.com/probot/probot)
|
||||
that locks closed issues and pull requests after a period of inactivity.
|
||||
|
||||

|
||||
|
||||
## Supporting the Project
|
||||
|
||||
Lock Threads is an MIT-licensed open source project. Its ongoing
|
||||
development is made possible thanks to the support of awesome backers.
|
||||
If you'd like to join them, please consider contributing with
|
||||
[Patreon](https://goo.gl/UtCEg4), [PayPal](https://goo.gl/BfygYx)
|
||||
or [Bitcoin](https://goo.gl/uJUAaU).
|
||||
|
||||
## Usage
|
||||
|
||||
1. **[Install the GitHub App](https://github.com/apps/lock)**
|
||||
2. Create `.github/lock.yml` based on the template below
|
||||
3. It will start scanning for closed issues and/or pull requests within an hour
|
||||
|
||||
#### Configuration
|
||||
|
||||
Create `.github/lock.yml` in the default branch to enable the app.
|
||||
The file can be empty, or it can override any of these default settings:
|
||||
|
||||
```yml
|
||||
# Configuration for lock-threads - https://github.com/dessant/lock-threads
|
||||
|
||||
# Number of days of inactivity before a closed issue or pull request is locked
|
||||
daysUntilLock: 365
|
||||
# Comment to post before locking. Set to `false` to disable
|
||||
lockComment: >
|
||||
This thread has been automatically locked because it has not had recent
|
||||
activity. Please open a new issue for related bugs and link to relevant
|
||||
comments in this thread.
|
||||
# Limit to only `issues` or `pulls`
|
||||
# only: issues
|
||||
```
|
||||
|
||||
## How are issues and pull requests determined to be inactive?
|
||||
|
||||
The app uses GitHub's [updated](https://git.io/vbR9z) search qualifier
|
||||
to determine inactivity. Any change to an issue or pull request
|
||||
is considered an update, including comments, changing labels,
|
||||
applying or removing milestones, or pushing commits.
|
||||
|
||||
An easy way to check and see which issues or pull requests will initially
|
||||
be locked is to add the `updated` search qualifier to either the issue
|
||||
or pull request page filter for your repository: `is:closed updated:<2016-12-20`.
|
||||
Adjust the date to be 365 days ago (or whatever you set for `daysUntilLock`)
|
||||
to see which issues or pull requests will be locked.
|
||||
|
||||
## Why are only some issues and pull requests locked?
|
||||
|
||||
To avoid triggering abuse prevention mechanisms on GitHub, only 30 issues
|
||||
and pull requests will be locked per hour. If your repository has more
|
||||
than that, it will just take a few hours or days to lock them all.
|
||||
|
||||
## Deployment
|
||||
|
||||
See [docs/deploy.md](docs/deploy.md) if you would like to run your own
|
||||
instance of this app.
|
||||
|
||||
## License
|
||||
|
||||
Lock Threads is released under the terms of the MIT License.
|
||||
Please refer to the [LICENSE](LICENSE) file.
|
||||
28
assets/app-description.md
Normal file
28
assets/app-description.md
Normal file
@@ -0,0 +1,28 @@
|
||||
A GitHub App that locks closed issues and pull requests.
|
||||
|
||||

|
||||
|
||||
## Usage
|
||||
|
||||
1. **[Install the GitHub App](https://github.com/apps/lock)**
|
||||
2. Create `.github/lock.yml` based on the template below
|
||||
3. It will start scanning for closed issues and/or pull requests within an hour
|
||||
|
||||
#### Configuration
|
||||
|
||||
Create `.github/lock.yml` in the default branch to enable the app.
|
||||
The file can be empty, or it can override any of these default settings:
|
||||
|
||||
```yml
|
||||
# Configuration for lock-threads - https://github.com/dessant/lock-threads
|
||||
|
||||
# Number of days of inactivity before a closed issue or pull request is locked
|
||||
daysUntilLock: 365
|
||||
# Comment to post before locking. Set to `false` to disable
|
||||
lockComment: >
|
||||
This thread has been automatically locked because it has not had recent
|
||||
activity. Please open a new issue for related bugs and link to relevant
|
||||
comments in this thread.
|
||||
# Limit to only `issues` or `pulls`
|
||||
# only: issues
|
||||
```
|
||||
BIN
assets/screenshot.png
Executable file
BIN
assets/screenshot.png
Executable file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
11
docs/deploy.md
Normal file
11
docs/deploy.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Deploying
|
||||
|
||||
If you would like to run your own instance of this app, see the
|
||||
[docs for deployment](https://probot.github.io/docs/deployment/).
|
||||
|
||||
This app requires these **Permissions & events** for the GitHub App:
|
||||
|
||||
- Issues - **Read & Write**
|
||||
- Pull requests - **Read & Write**
|
||||
- Single File - **Read-only**
|
||||
- Path: `.github/lock.yml`
|
||||
30
package.json
Normal file
30
package.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "lock-threads",
|
||||
"version": "0.1.0",
|
||||
"description":
|
||||
"A GitHub App built with Probot that locks closed issues and pull requests.",
|
||||
"author": "Armin Sebastian",
|
||||
"license": "MIT",
|
||||
"repository": "https://github.com/dessant/lock-threads",
|
||||
"scripts": {
|
||||
"start": "probot run ./src/index.js",
|
||||
"watch": "nodemon --exec 'npm start'",
|
||||
"update": "ncu --upgrade --upgradeAll && yarn",
|
||||
"push": "git push --follow-tags origin master",
|
||||
"release": "standard-version && yarn run push"
|
||||
},
|
||||
"dependencies": {
|
||||
"probot": "^3.0.3",
|
||||
"probot-scheduler": "^1.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"localtunnel": "^1.8.3",
|
||||
"nodemon": "1.12.5",
|
||||
"npm-check-updates": "^2.13.0",
|
||||
"standard-version": "^4.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "8.9.0",
|
||||
"npm": "5.5.1"
|
||||
}
|
||||
}
|
||||
7
src/defaults.js
Normal file
7
src/defaults.js
Normal file
@@ -0,0 +1,7 @@
|
||||
module.exports = {
|
||||
daysUntilLock: 365,
|
||||
lockComment:
|
||||
'This thread has been automatically locked because ' +
|
||||
'it has not had recent activity. Please open a new issue ' +
|
||||
'for related bugs and link to relevant comments in this thread.'
|
||||
};
|
||||
21
src/index.js
Normal file
21
src/index.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const createScheduler = require('probot-scheduler');
|
||||
|
||||
const App = require('./lock');
|
||||
|
||||
module.exports = robot => {
|
||||
scheduler = createScheduler(robot);
|
||||
|
||||
robot.on('schedule.repository', async context => {
|
||||
const app = await getApp(context);
|
||||
if (app) {
|
||||
await app.lock();
|
||||
}
|
||||
});
|
||||
|
||||
async function getApp(context) {
|
||||
let config = await context.config('lock.yml');
|
||||
if (config) {
|
||||
return new App(context, config, robot.log);
|
||||
}
|
||||
}
|
||||
};
|
||||
68
src/lock.js
Normal file
68
src/lock.js
Normal file
@@ -0,0 +1,68 @@
|
||||
const defaults = require('./defaults');
|
||||
|
||||
module.exports = class Lock {
|
||||
constructor(context, config, logger) {
|
||||
this.context = context;
|
||||
this.config = Object.assign({}, defaults, config);
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
async lock() {
|
||||
const {owner, repo} = this.context.repo();
|
||||
const {lockComment} = this.config;
|
||||
|
||||
const issues = await this.getLockableIssues();
|
||||
for (const issue of issues) {
|
||||
const issueUrl = `${owner}/${repo}/issues/${issue.number}`;
|
||||
if (lockComment) {
|
||||
this.logger.info(`[${issueUrl}] Commenting`);
|
||||
await this.context.github.issues.createComment({
|
||||
owner,
|
||||
repo,
|
||||
number: issue.number,
|
||||
body: lockComment
|
||||
});
|
||||
}
|
||||
|
||||
this.logger.info(`[${issueUrl}] Locking`);
|
||||
await this.context.github.issues.lock({
|
||||
owner,
|
||||
repo,
|
||||
number: issue.number
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async getLockableIssues() {
|
||||
const results = await this.search();
|
||||
return results.data.items.filter(issue => !issue.locked);
|
||||
}
|
||||
|
||||
search() {
|
||||
const {owner, repo} = this.context.repo();
|
||||
const {daysUntilLock, only} = this.config;
|
||||
const timestamp = this.since(daysUntilLock)
|
||||
.toISOString()
|
||||
.replace(/\.\d{3}\w$/, '');
|
||||
|
||||
let query = `repo:${owner}/${repo} is:closed updated:<${timestamp}`;
|
||||
if (only === 'issues') {
|
||||
query += ` is:issue`;
|
||||
} else if (only === 'pulls') {
|
||||
query += ` is:pr`;
|
||||
}
|
||||
|
||||
this.logger.info(`[${owner}/${repo}] Searching`);
|
||||
return this.context.github.search.issues({
|
||||
q: query,
|
||||
sort: 'updated',
|
||||
order: 'desc',
|
||||
per_page: 30
|
||||
});
|
||||
}
|
||||
|
||||
since(days) {
|
||||
const ttl = days * 24 * 60 * 60 * 1000;
|
||||
return new Date(new Date() - ttl);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user