Document the CLI to use a single command and improve the readability
This commit is contained in:
Родитель
cd28f288d5
Коммит
0bbc3a082e
|
@ -1,5 +1,5 @@
|
|||
.ghec-audit-log
|
||||
|
||||
.last-cursor-update
|
||||
|
||||
# Created by https://www.gitignore.io/api/node
|
||||
# Edit at https://www.gitignore.io/?templates=node
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
Copyright <2020> <Javier de Pedro López>
|
||||
|
||||
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.
|
22
README.md
22
README.md
|
@ -9,7 +9,7 @@ You can build an sh script on top of this one to store the data or query it.
|
|||
### CLI arguments
|
||||
This script can take the following arguments:
|
||||
```
|
||||
> node audit-log-ghec-cli.js "--help"
|
||||
> node ghec-audit-log-cli.js "--help"
|
||||
|
||||
Usage: audit-log-ghec-cli [options]
|
||||
|
||||
|
@ -39,10 +39,24 @@ Execute the command using node or npm.
|
|||
|
||||
#### npm
|
||||
```shell script
|
||||
npm run start -- --pretty
|
||||
$ npm run start -- --pretty
|
||||
```
|
||||
|
||||
### node
|
||||
```shell script
|
||||
node audit-log-ghec-cli --pretty
|
||||
```
|
||||
$ node audit-log-ghec-cli --pretty
|
||||
```
|
||||
|
||||
### Installing as CLI
|
||||
|
||||
Optionally you can install the script as a CLI and run it from the command line. To install it run:
|
||||
```shell script
|
||||
$ git clone https://github.com/droidpl/ghec-audit-log-cli
|
||||
$ cd ghec-audit-log-cli
|
||||
$ npm link
|
||||
```
|
||||
|
||||
Then you can execute the script as a CLI using:
|
||||
```shell script
|
||||
$ ghec-audit-log-cli -v
|
||||
```
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const {allEntriesQuery, newEntriesQuery} = require('./audit-log-queries');
|
||||
const {allEntriesQuery, newEntriesQuery} = require('./ghec-audit-log-queries');
|
||||
|
||||
async function requestAllEntries(requestExecutor, org){
|
||||
let entries = [];
|
||||
|
@ -9,13 +9,13 @@ async function requestAllEntries(requestExecutor, org){
|
|||
|
||||
let firstPageCursor = null;
|
||||
let hasNextPage = true;
|
||||
while(hasNextPage) {
|
||||
// while(hasNextPage) {
|
||||
const data = await requestExecutor(allEntriesQuery, variables);
|
||||
entries = entries.concat(data.organization.auditLog.nodes);
|
||||
hasNextPage = data.organization.auditLog.pageInfo.hasNextPage;
|
||||
variables.page = data.organization.auditLog.pageInfo.endCursor;
|
||||
if(!firstPageCursor) firstPageCursor = data.organization.auditLog.pageInfo.startCursor
|
||||
}
|
||||
// }
|
||||
return {data: entries, newestCursor: firstPageCursor};
|
||||
}
|
||||
|
|
@ -1,7 +1,8 @@
|
|||
#! /usr/bin/env node
|
||||
const YAML = require('yaml');
|
||||
const fs = require('fs');
|
||||
const {graphql} = require('@octokit/graphql');
|
||||
const {requestNewestEntries, requestAllEntries} = require('./audit-log-client');
|
||||
const {requestNewestEntries, requestAllEntries} = require('./ghce-audit-log-client');
|
||||
|
||||
//---- Obtain configuration
|
||||
const { program } = require('commander');
|
||||
|
@ -23,7 +24,7 @@ const pretty = program.pretty || false;
|
|||
const token = program.token || config.token;
|
||||
const org = program.org || config.org;
|
||||
|
||||
//TODO maybe support other format like PUTVAL?
|
||||
//TODO idea: maybe add support for other formats like PUTVAL to forward the data in an easier way
|
||||
|
||||
//---- Run validation
|
||||
if (!token) {
|
|
@ -5,9 +5,9 @@ const auditEntry = `
|
|||
}
|
||||
`;
|
||||
|
||||
const auditLogEntries = `
|
||||
const ghecAuditLogEntries = `
|
||||
__typename
|
||||
${auditEntry}
|
||||
`;
|
||||
|
||||
module.exports = auditLogEntries;
|
||||
module.exports = ghecAuditLogEntries;
|
|
@ -1,9 +1,9 @@
|
|||
const auditLogEntries = require('./audit-log-entries');
|
||||
const auditLogEntries = require('./ghec-audit-log-entries');
|
||||
|
||||
const allEntriesQuery = `
|
||||
query($org: String!, $page: String) {
|
||||
organization(login: $org) {
|
||||
auditLog(first: 100, after: $page){
|
||||
auditLog(first: 1, after: $page){
|
||||
pageInfo {
|
||||
startCursor
|
||||
endCursor
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "ghec-audit-log-js",
|
||||
"name": "ghec-audit-log-cli",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
|
|
17
package.json
17
package.json
|
@ -1,17 +1,24 @@
|
|||
{
|
||||
"name": "ghec-audit-log-js",
|
||||
"name": "ghec-audit-log-cli",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "audit-log-ghec-cli.js",
|
||||
"main": "ghec-audit-log-cli.js",
|
||||
"scripts": {
|
||||
"start": "node audit-log-ghec-cli.js"
|
||||
"start": "node ghec-audit-log-cli"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/droidpl/ghec-audit-log-cli.git"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"author": "Javier de Pedro López <droidpl@github.com>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@octokit/graphql": "^4.3.1",
|
||||
"commander": "^5.1.0",
|
||||
"yaml": "^1.9.2"
|
||||
},
|
||||
"bin": {
|
||||
"ghec-audit-log-cli": "./ghec-audit-log-cli.js"
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче