Skip to content

Commit

Permalink
drop outside of repo project support
Browse files Browse the repository at this point in the history
too hard to get the tokens, maybe reimplement in the feature...
  • Loading branch information
Logerfo committed Nov 8, 2019
1 parent 0cd0e6c commit e81b434
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 137 deletions.
28 changes: 0 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ jobs:
name: Triage
runs-on: ubuntu-16.04
steps:
- uses: actions/checkout@master
- uses: Logerfo/triage-action@0.0.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -41,41 +40,14 @@ jobs:
name: Triage
runs-on: ubuntu-16.04
steps:
- uses: actions/checkout@master # Not needed if project is set to false
- uses: Logerfo/triage-action@0.0.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }} # The `GITHUB_TOKEN` secret.
label: triage # The triage label of your repository.
project: true # Enable or disable the idea that adding an issue to a project drops its triage state.
milestone: true # Enable or disable the idea that setting a milestone to an issue drops its triage state.
config-path: .github/triage.yml # The path of the addtional configurations file. Only useful if project is set to true.
```

### Additional configurations file
If `project: true`, you may need create a additional configuration file. The default path is `.github/triage.yml`, but you can change it in the action configuration file, as shown above.
This file allows you to set extra project sources (users and organizations) to look for the issue being analyzed by the action. The host repository will always be looked by default.
The file must follow the following structure:
```yml
owner:
token: <token>
type: <user|organization>

include: [1, 2]
# or
exclude: [3, 4]
```
For example:
```yml
dotnet:
token: ${{ secrets.DOTNET_TOKEN }}
type: organization
include: [1]
```
You cannot apply both the `include` and the `exclude` attributes at the same time. If you apply the `include` attribute, only the listed projects ids will be looked. If you apply the `exclude` attributes, every project will be looked, except for the listed ones. If you apply none of them, every project will be looked, no exceptions. If you apply both of them, the action will fail.
The token is mandatory, even for public projects. For security reasons, it's recommended that you add the tokens as secrets in your host repository.
Click [here](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) to known how to create an access token.
Click [here](https://help.github.com/en/github/automating-your-workflow-with-github-actions/creating-and-using-encrypted-secrets) to known how to create a secret.

### Auto update
You can use (at your own risk) the `release` branch instead of the specific version tag.
Never user `master`, since the distribution file does not exist in this branch and the action will always fail.
Expand Down
3 changes: 0 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ inputs:
milestone:
description: Enable or disable the idea that setting a milestone to an issue drops its triage state.
default: true
config-path:
description: The optional configuration file path.
default: .github/triage.yml

runs:
using: 'node12'
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
},
"dependencies": {
"@actions/core": "1.2.0",
"@actions/github": "1.1.0",
"js-yaml": "3.13.1"
"@actions/github": "1.1.0"
},
"devDependencies": {
"eslint": "6.6.0",
Expand Down
144 changes: 40 additions & 104 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
const path = require("path"),
fs = require("fs").promises,
yaml = require("js-yaml"),
const fs = require("fs").promises,
core = require("@actions/core"),
github = require("@actions/github");

const REPO_DIRECTORY = process.env["GITHUB_WORKSPACE"],
CONFIG_PATH = path.join(REPO_DIRECTORY, getInput("config-path", ".github/target-label.yml")),
token = core.getInput("github-token", { required: true }),
const token = core.getInput("github-token", { required: true }),
label = getInput("label", "triage"),
project = getInput("project", "true") == "true",
milestone = getInput("milestone", "true") == "true",
Expand All @@ -17,23 +13,6 @@ const REPO_DIRECTORY = process.env["GITHUB_WORKSPACE"],

const getEvent = async () => JSON.parse(await fs.readFile(process.env["GITHUB_EVENT_PATH"]));

async function getYamlConfig() {
try {
const text = await fs.readFile(CONFIG_PATH);
return yaml.safeLoad(text);
}
catch (err) {
core.debug(err);
return undefined;
}
}

async function getConfig() {
const ymlConfig = await getYamlConfig();
core.debug(JSON.stringify(ymlConfig));
return ymlConfig;
}

function getInput(name, fallback) {
const input = core.getInput(name);
return input || fallback;
Expand Down Expand Up @@ -87,90 +66,47 @@ function labelMap(label) {
return label.name;
}

async function* getProjectConfigs() {
yield {
client: client,
function: "listForRepo",
argument: {
async function projectContained() {
let projectPage = 0,
projectsResult;
do {
core.info(`Projects page ${++projectPage}:`);
projectsResult = await client.projects.listForRepo({
owner,
page: projectPage,
repo,
},
};
const config = await getConfig();
for (const project of Object.values(config)) {
if (!["organization", "user"].includes(project.type)) {
core.setFailed(`${project}.type is supposed to be "organization" or "user". Failing...`);
return;
}
if (project.include && project.exclude) {
core.setFailed(`${project} has both "include" and "exclude" set simultaneously. Failing...`);
return;
}
const obj = {
client: new github.GitHub(project.token),
argument: {
owner,
repo,
},
include: project.include,
exclude: project.exclude
};
if (project.type == "organization") {
obj.function = "listForOrg";
obj.argument.org = project;
}
else {
obj.function = "listForUser";
obj.argument.username = project;
}
yield obj;
}
}

async function projectContained() {
for await (const config of getProjectConfigs()) {
let projectPage = 0,
projectsResult;
do {
core.info(`Projects page ${++projectPage}:`);
config.argument.page = projectPage;
projectsResult = await config.client.projects[config.function](config.argument);
core.debug(JSON.stringify(projectsResult.data));
for (const project of projectsResult.data) {
if (config.include && !config.include.includes(project.id)
|| config.exclude && config.exclude.includes(project.id)) {
continue;
}
let columnPage = 0,
columnsResult;
do {
core.info(`Columns page ${++columnPage}:`);
columnsResult = await client.projects.listColumns({
project_id: project.id,
});
core.debug(JSON.stringify(columnsResult.data));
for (const column of columnsResult.data) {
let cardPage = 0,
cardsResult;
do {
core.info(`Cards page ${++cardPage}:`);
cardsResult = await client.projects.listCards({
column_id: column.id
});
core.debug(JSON.stringify(cardsResult.data));
for (const card of cardsResult.data) {
const items = card.url.split('/');
const id = items[items.length - 1];
if (context.payload.issue.number == id) {
return true;
}
});
core.debug(JSON.stringify(projectsResult.data));
for (const project of projectsResult.data) {
let columnPage = 0,
columnsResult;
do {
core.info(`Columns page ${++columnPage}:`);
columnsResult = await client.projects.listColumns({
project_id: project.id,
});
core.debug(JSON.stringify(columnsResult.data));
for (const column of columnsResult.data) {
let cardPage = 0,
cardsResult;
do {
core.info(`Cards page ${++cardPage}:`);
cardsResult = await client.projects.listCards({
column_id: column.id
});
core.debug(JSON.stringify(cardsResult.data));
for (const card of cardsResult.data) {
const items = card.url.split('/');
const id = items[items.length - 1];
if (context.payload.issue.number == id) {
return true;
}
} while (cardsResult.data.length == 100);
}
} while (columnsResult.data.length == 100);
}
} while (projectsResult.data.length == 100);
}
}
} while (cardsResult.data.length == 100);
}
} while (columnsResult.data.length == 100);
}
} while (projectsResult.data.length == 100);
return false;
}

Expand Down

0 comments on commit e81b434

Please sign in to comment.