Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add missing files #76

Merged
merged 3 commits into from
Apr 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: Renato66
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Unit test
name: Checks

on:
pull_request:
Expand All @@ -17,4 +17,5 @@ jobs:
restore-keys: |
${{ runner.os }}-bun-${{ github.ref }}
- run: bun install
- run: bun tslint
- run: bun test
6 changes: 6 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
- uses: actions/cache@v3
with:
path: ~/.bun
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
restore-keys: |
${{ runner.os }}-bun-${{ github.ref }}
- run: bun install
- run: bun test --coverage
#
Expand Down
10 changes: 10 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid"
}
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"streetsidesoftware.code-spell-checker",
"esbenp.prettier-vscode"
]
}
30 changes: 30 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Bun

> [!NOTE]
> You will need to have [bun](https://bun.sh/docs/installation) installed

To install dependencies:

```bash
bun install
```

To run:

```bash
bun run test
```

This project was created using `bun init` in bun v1.1.0. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.

# Docker

> [!NOTE]
> You will need to have [docker](https://www.docker.com/products/docker-desktop/) installed


To create a docker image:

```
docker build --pull -t auto-label .
```
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

The MIT License (MIT)

Copyright (c) 2018-2024 Renato Vicente and contributors

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.
127 changes: 119 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,126 @@
# auto-label
# Auto-label

To install dependencies:
![Unit test](https://github.com/Renato66/auto-label/workflows/Unit%20test/badge.svg)
[![Auto Label](https://github.com/Renato66/auto-label/workflows/Labeling%20new%20issue/badge.svg)](https://github.com/Renato66/auto-label)
[![codecov](https://codecov.io/gh/Renato66/auto-label/branch/master/graph/badge.svg)](https://codecov.io/gh/Renato66/auto-label)

![image](https://user-images.githubusercontent.com/9284273/79672530-57c1db80-81a9-11ea-900c-3b4f73984e0a.png)

The Auto label action will check for every new issue and automatically adds a label based on the body of the issue. This means that finding specific issues will be much easier.

> [!WARNING]
> The main branch is being refactored, use the stable one at [master](https://github.com/Renato66/auto-label/tree/master) subscribe to [v3](https://github.com/Renato66/auto-label/issues/75) to get the latest version when it's released

## Creating

Check out the app to make a YAML file
[https://renato66.github.io/auto-label/](https://renato66.github.io/auto-label/)

Renato66 marked this conversation as resolved.
Show resolved Hide resolved
or

add a file to `.github/workflows/issue.yml`

```yml
name: Labeling new issue
on:
issues:
types: ['opened']
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: Renato66/auto-label@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
ignore-comments: true
labels-synonyms: '{"bug":["error","need fix","not working"],"enhancement":["upgrade"],"question":["help"]}'
labels-not-allowed: '["good first issue"]'
default-labels: '["help wanted"]'
```

## Inputs

| Name | Description | Required | Default | Examples |
| ------------------ | ----------------------------------- | -------- | ------- | :------------------------: |
| repo-token | GitHub token for the repository | true | - | [...](#repo-token) |
| ignore-comments | Ignore labels inside issue comments | false | true | [...](#ignore-comments) |
| labels-synonyms | Text synonyms for labels | false | - | [...](#labels-synonyms) |
| labels-not-allowed | Labels to ignore | false | - | [...](#labels-not-allowed) |
| default-labels | Labels that will always be set | false | - | [...](#default-labels) |

Renato66 marked this conversation as resolved.
Show resolved Hide resolved
### Repo Token

Repo token is provided automatically by GitHub; just need to add

```
repo-token: ${{ secrets.GITHUB_TOKEN }}
```

#### Change bot appearance

If you want to change who added the labels, you can provide a user token

![image](https://user-images.githubusercontent.com/9284273/79672221-678bf080-81a6-11ea-908e-fb875772121a.png)

![image](https://user-images.githubusercontent.com/9284273/79672289-e123de80-81a6-11ea-9faa-237adc0873f0.png)

The [token](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line) will only need the `public_repo` scope

You will need to provide it as [secret](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets) `GITHUB_USER_TOKEN`
and update the issue.yml repo-token with:
`repo-token: ${{ secrets.GITHUB_USER_TOKEN }}`

### Ignore Comments

If you prefer to leave as default (true) You can provide a list of labels in a [template](https://help.github.com/en/github/building-a-strong-community/configuring-issue-templates-for-your-repository#configuring-the-template-chooser) for the author to choose which labels are available to pick
But if you prefer to set it as false, the author can set the labels inside a comment so it doesn't appear on issue body

### Scoped blocks

You can set a custom part of your issue/pr to be labeled using this structure:

```
Some text that could have a label that wouldn't be set
<!-- AUTO-LABEL:START -->
Another text that could have a label and will be set as a label
<!-- AUTO-LABEL:END -->
```

thanks to [@dielduarte](https://github.com/dielduarte) and [@PauloGoncalvesBH](https://github.com/PauloGoncalvesBH)

### Labels Synonyms

Sometimes labels can be set upon other texts, as an example, if you have a label like `C: VCombobox` it would be hard to match the label in a normal issue, but you can provide a JSON to set it synonyms:

```bash
bun install
```
labels-synonyms: '{"C: VCombobox":["combobox","v-combobox","combo box"]}'
```

### Labels Not Allowed

To run:
Some labels are restricted to repo owners such as `needs priority` `testing` `won't fix` they can be set in an Array form:

```bash
bun run index.ts
```
labels-not-allowed: '["needs priority","testing","won't fix"]'
```

This project was created using `bun init` in bun v1.1.0. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
### Default Labels

Labels that will always be set when an issue is created/updated such as `triage`, they can be set in an Array form:

```
default-labels: '["triage"]'
```

## Badge

To add a badge simple replace owner and repository

<!-- Replace <OWNER> and <REPOSITORY>. It assumes workflow name is "Labeling%20new%20issue" -->

[![Auto Label](https://github.com/Renato66/auto-label/workflows/Labeling%20new%20issue/badge.svg)](https://github.com/Renato66/auto-label)

```
<!-- Replace <OWNER> and <REPOSITORY>. It assumes workflow name is "Labeling%20new%20issue" -->
[![Auto Label](https://github.com/<OWNER>/<REPOSITORY>/workflows/Labeling%20new%20issue/badge.svg)](https://github.com/Renato66/auto-label)
```
Binary file modified bun.lockb
Binary file not shown.
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
"version": "3.0.0",
"module": "src/index.ts",
"type": "module",
"scripts": {
"test": "bun test",
"coverage": "bun test --coverage",
"tslint": "bun run node_modules/typescript/lib/tsc.js --noEmit"
},
"devDependencies": {
"@types/bun": "latest",
"nock": "^13.5.4"
"nock": "^13.5.4",
"typescript": "^5.4.4"
},
"peerDependencies": {
"typescript": "^5.0.0"
Expand Down
16 changes: 8 additions & 8 deletions src/domain/labelsNotAllowed.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as core from "@actions/core";
import * as core from '@actions/core'
export const removeLabelsNotAllowed = (labels: string[]): string[] => {
const labelsNotAllowed = core.getInput("labels-not-allowed");
const labelsNotAllowed = core.getInput('labels-not-allowed')
if (!labelsNotAllowed) {
return labels;
return labels
}
const labelsToIgnore = JSON.parse(core.getInput("labels-not-allowed"));
const labelsToIgnore = JSON.parse(core.getInput('labels-not-allowed'))
return labels.filter((elem: string) => {
return (
labelsToIgnore.find((label: string) => {
return label.toLowerCase() === elem.toLowerCase();
return label.toLowerCase() === elem.toLowerCase()
}) === undefined
);
});
};
)
})
}
4 changes: 2 additions & 2 deletions src/scraper/text.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as core from '@actions/core'

const escapeRegExp: Function = (string: String): String => {
const escapeRegExp = (string: String): String => {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') // $& means the whole matched string
}

const compareLabels = (labels: string[]): (line: string) => string[] => {
const compareLabels = (labels: string[]): ((line: string) => string[]) => {
const labelsSynonyms = getLabelsSynonyms()
const hasSynonyms = Object.keys(labelsSynonyms).length !== 0
if (hasSynonyms) {
Expand Down
38 changes: 19 additions & 19 deletions src/service/github.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import * as github from "@actions/github";
import * as github from '@actions/github'

// TODO: get github type
const getRepoLabels = async (client: any): Promise<string[]> => {
let list: any = [];
let page: number = 1;
let hasMorePages: Boolean = false;
let list: any = []
let page: number = 1
let hasMorePages: Boolean = false
do {
const { data: labelList } = await client.rest.issues.listLabelsForRepo({
const {data: labelList} = await client.rest.issues.listLabelsForRepo({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
per_page: 100,
page: page,
});
list = [...list, ...labelList];
hasMorePages = labelList.length === 100;
page++;
} while (hasMorePages);
page: page
})
list = [...list, ...labelList]
hasMorePages = labelList.length === 100
page++
} while (hasMorePages)

return list.map((elem: any) => {
return elem.name;
});
};
return elem.name
})
}

const addLabels: Function = async (
const addLabels = async (
client: any,
issueNumber: number,
labels: string[]
Expand All @@ -31,7 +31,7 @@ const addLabels: Function = async (
owner: github.context.repo.owner,
repo: github.context.repo.repo,
issue_number: issueNumber,
labels: labels,
});
};
export { getRepoLabels, addLabels };
labels: labels
})
}
export {getRepoLabels, addLabels}
Loading