Skip to content

Commit 3071586

Browse files
committed
adjust autofixer for coder/coder
1 parent 6802cb0 commit 3071586

19 files changed

+167
-434
lines changed

.github/workflows/autofix.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Automatically fix all software bugs
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * 0'
6+
7+
jobs:
8+
scheduled:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Check out this repo
12+
uses: actions/checkout@v2
13+
- name: Run autofix
14+
env:
15+
GITHUB_TOKEN: ${{ secrets.CODERAUTOFIX_GITHUB_TOKEN }}
16+
run: |-
17+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
18+
brew install gh
19+
20+
git clone https://github.com/coder/coder
21+
cd coder
22+
23+
../bin/autofix --branches --pull-request

.github/workflows/npm-publish.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.gitpod.dockerfile

Lines changed: 0 additions & 3 deletions
This file was deleted.

.gitpod.yml

Lines changed: 0 additions & 19 deletions
This file was deleted.

README.md

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# Autofix
22

3-
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-ready--to--code-908a85?logo=gitpod)](https://gitpod.io/#https://github.com/autofix-dev/autofix)
4-
[![NPM version](https://img.shields.io/npm/v/autofix)](https://www.npmjs.com/package/autofix)
5-
63
Automatically fix all software bugs.
74

85

@@ -20,44 +17,15 @@ Preview all the commands this would run, but don't actually do anything:
2017
autofix --dry
2118
```
2219

23-
Autofix bugs, commit fixes into separate branches, push branches to a GitHub remote:
24-
25-
```bash
26-
autofix --branches --push=myremote
27-
```
28-
29-
Autofix bugs in a GitHub repository:
30-
31-
```bash
32-
autofix https://github.com/nodejs/node
33-
```
34-
35-
Autofix bugs in a GitHub repository, commit fixes, and automatically send pull requests (requires [hub](https://github.com/github/hub)):
36-
37-
```bash
38-
autofix https://github.com/nodejs/node --pull-request
39-
```
40-
41-
42-
## Try it online
43-
44-
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/autofix-dev/autofix)
45-
46-
47-
## Try it locally
48-
49-
If you have [npm](https://www.npmjs.com), you can already run `autofix` via `npx`:
20+
Autofix bugs in a GitHub repository, commit fixes into separate branches, and automatically send pull requests (requires [gh](https://github.com/cli/cli)):
5021

5122
```bash
52-
npx autofix
23+
autofix --branches --pull-request
5324
```
5425

55-
Alternatively, can also install it like so:
56-
57-
```bash
58-
npm install -g autofix
59-
```
26+
## Dependencies
6027

28+
- [gh](https://github.com/cli/cli)
6129

6230
## Command line options
6331

@@ -78,26 +46,18 @@ OPTIONS:
7846
- [x] `--pull-request`: Automatically open pull requests with pushed commits (requires [hub](https://github.com/github/hub), implies `--push=origin` if unspecified)
7947
- [x] `--branch-suffix=SUFFIX`: Add a common suffix to generated branch names (i.e. `autofix-codespell-SUFFIX`)
8048
- [x] `--signoff`: Use Git's `--signoff` (or `-s`) feature when creating commits
81-
- [ ] `--circle-ci`: Run this autofix weekly on CircleCI (adds a `.circleci/config.yml` file)
82-
8349

8450
## Types of bugs that can be fixed
8551

8652
Tier 0 (no rework needed):
8753
- [x] Remove trailing whitespace (uses `git`, `xargs` and `sed`)
88-
- [x] Update pinned pyenv tool versions in Dockerfiles (requires `pyenv`)
89-
- [x] Update pinned nvm tool versions in Dockerfiles (requires `nvm`)
90-
- [x] Update pinned sdkman tool versions in Dockerfiles (requires [sdkman](https://github.com/sdkman/sdkman-cli))
91-
- [x] Update pinned rr versions in Dockerfiles
92-
- [x] Update some pinned Go module versions in Dockerfiles
54+
- [x] Applies `make fmt` on the coder/coder codebase.
55+
- [x] Update version of terraform in the coder/coder codebase.
9356
- [x] Update Git submodules
9457

9558
Tier 1 (some rework might be needed):
96-
- [x] Fix typos & spelling mistakes (requires [codespell](https://github.com/codespell-project/codespell/))
9759

9860
Tier 2 (experimental, use with caution):
99-
- [x] Fix C++ bugs with `clang-tidy` (requires [clang-tidy](http://clang.llvm.org/extra/clang-tidy/))
100-
- [ ] Fix Rust bugs with `clippy` (requires [rust-clippy](https://github.com/rust-lang-nursery/rust-clippy/))
10161

10262
Tier 3 (you probably don't want to run these):
10363
- [ ] TODO

autofix.js

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Promise.all([...coreFixers, ...customFixers].map(async (fixer) => {
7878
const fixBranch = argv.branches ? `autofix-${fixer.id}${argv['branch-suffix'] ? '-' + argv['branch-suffix'] : ''}` : baseBranch;
7979
if (argv.branches) {
8080
// If --branches was passed, create a dedicated branch for this fixer.
81+
await exec(`git branch -D ${fixBranch} 2>&1 || true`);
8182
await exec(`git checkout -b ${fixBranch} ${baseBranch} 2>&1`);
8283
}
8384

@@ -100,7 +101,8 @@ Promise.all([...coreFixers, ...customFixers].map(async (fixer) => {
100101
// Attempt to commit any changes (will fail if there is no change).
101102
let committed = false;
102103
try {
103-
await exec(`git commit -a${argv.signoff ? 's' : ''}m "Autofix: ${fixer.id}" 2>/dev/null`);
104+
await exec(`git commit -a${argv.signoff ? 's' : ''}m "chore(autofix): ${fixer.id} \n
105+
Automatically generated via https://github.com/coder/autofix" 2>/dev/null`);
104106
committed = true;
105107
if (!argv.dry) {
106108
console.log(` Fixes committed!`);
@@ -114,11 +116,12 @@ Promise.all([...coreFixers, ...customFixers].map(async (fixer) => {
114116

115117
if (committed && pushRemote) {
116118
// If fixes were committed, and --push=myremote or --pull-request were passed, push to the appropriate remote.
119+
await exec(`git push ${pushRemote} :${fixBranch} 2>&1 || true`);
117120
await exec(`git push ${pushRemote} ${fixBranch} 2>&1`);
118121

119122
if (argv['pull-request']) {
120123
// If --pull-request was passed, open a Pull Request from the pushed branch to the upstream repository's default branch.
121-
await exec(`hub pull-request --head "${pushRemote}:${fixBranch}" --no-edit`);
124+
await exec(`gh pr create --repo coder/coder --head ${fixBranch} --fill`);
122125
}
123126
}
124127

@@ -127,10 +130,7 @@ Promise.all([...coreFixers, ...customFixers].map(async (fixer) => {
127130
await exec(`git checkout ${baseBranch} 2>&1`);
128131
// Also return any Git submodules to their original state.
129132
await exec(`git submodule update --force`);
130-
if (!committed) {
131-
// If no fixes were committed, delete the dedicated branch again.
132-
await exec(`git branch -D ${fixBranch}`)
133-
}
133+
await exec(`git branch -D ${fixBranch} || true`)
134134
}
135135
}
136136
}
@@ -143,31 +143,8 @@ Promise.all([...coreFixers, ...customFixers].map(async (fixer) => {
143143

144144
'find . -not -iwholename "*.git*" -type f -print0 | xargs -0 perl -pi -e "s/\\s+$//"'
145145

146-
'./mach lint .'
147-
148-
'./mach static-analysis check .'
149-
150-
'performance-faster-string-find'
151-
152-
'git submodule foreach git fetch && git submodule update --remote'
153-
154146
// Tier 1
155147

156-
'codespell -w 2>/dev/null'
157-
158148
// Tier 2
159149

160-
'android-cloexec-accept'
161-
'android-cloexec-accept4'
162-
'android-cloexec-creat'
163-
'android-cloexec-dup'
164-
'android-cloexec-epoll-create'
165-
'android-cloexec-epoll-create1'
166-
'android-cloexec-fopen'
167-
'android-cloexec-inotify-init'
168-
'android-cloexec-inotify-init1'
169-
'android-cloexec-memfd-create'
170-
'android-cloexec-open'
171-
'android-cloexec-socket'
172-
173150
// Tier 3

fixers.disabled/make-fmt.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright © 2022 Geoffrey Huntley.
2+
// The following code is covered by the MIT license.
3+
4+
const util = require('util');
5+
6+
exports.register = async (fixers) => {
7+
fixers[0].push({
8+
id: 'make-fmt',
9+
cmd: 'make fmt > /dev/null 2>&1',
10+
description: 'Fix formatting mistakes',
11+
});
12+
};

fixers.disabled/make-gen.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright © 2022 Geoffrey Huntley.
2+
// The following code is covered by the MIT license.
3+
4+
const util = require('util');
5+
6+
exports.register = async (fixers) => {
7+
fixers[0].push({
8+
id: 'make-gen',
9+
cmd: 'make gen > /dev/null 2>&1',
10+
description: 'Fix generated files',
11+
});
12+
};

fixers/clang-tidy.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

fixers/codespell.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

fixers/trailing-spaces.js

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright © 2022 Geoffrey Huntley.
2+
// The following code is covered by the MIT license.
3+
4+
const util = require('util');
5+
const exec = util.promisify(require('child_process').exec);
6+
7+
exports.register = async (fixers) => {
8+
fixers[0].push({
9+
id: 'upgrade-examples-terraform-provider-coder',
10+
cmd: 'examples/update_template_versions.sh > /dev/null 2>&1',
11+
description: 'Upgrade terraform-provider-coder version of coder/coder examples',
12+
});
13+
};

fixers/upgrade-go-modules.js

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)