-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e106d0d
Showing
7 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GITHUB_CLIENT_ID= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.env | ||
/tmp/ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import AuthFlow from "./modules/auth.js"; | ||
|
||
import { Select } from "https://deno.land/x/cliffy/prompt/select.ts"; | ||
import { config } from "https://deno.land/x/dotenv/mod.ts"; | ||
|
||
import { download_repos } from './modules/git.js'; | ||
|
||
config({ safe: true, export: true }); | ||
|
||
let octokit; | ||
|
||
while(true) { | ||
let options = { | ||
'download': { | ||
disabled: octokit === undefined, | ||
name: 'Download Repositories', | ||
action: async () => { | ||
await download_repos(octokit); | ||
} | ||
}, | ||
'delete': { | ||
disabled: octokit === undefined, | ||
name: 'Delete Repositories', | ||
action: async () => { | ||
console.log('start grading') | ||
} | ||
}, | ||
'auth': { | ||
disabled: false, | ||
name: 'Authenticate', | ||
action: async () => { | ||
octokit = await AuthFlow(); | ||
} | ||
}, | ||
'exit': { | ||
disabled: false, | ||
name: 'Exit', | ||
action: async () => { | ||
Deno.exit(); | ||
} | ||
} | ||
} | ||
|
||
const choice = await Select.prompt({ | ||
message: "What would you like to do?", | ||
options: Object.entries(options).map(([value, {name, disabled}]) => { | ||
return {value, name, disabled} | ||
}), | ||
}); | ||
|
||
await options[choice].action(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Octokit } from "https://cdn.skypack.dev/octokit?dts"; | ||
import { createOAuthDeviceAuth } from "https://cdn.pika.dev/@octokit/auth-oauth-device"; | ||
|
||
export default async function() { | ||
const octokit = new Octokit({ | ||
authStrategy: createOAuthDeviceAuth, | ||
auth: { | ||
clientType: "oauth-app", | ||
clientId: Deno.env.get('GITHUB_CLIENT_ID'), | ||
scopes: ["public_repo"], | ||
async onVerification (verification) { | ||
// verification example | ||
// { | ||
// device_code: "3584d83530557fdd1f46af8289938c8ef79f9dc5", | ||
// user_code: "WDJB-MJHT", | ||
// verification_uri: "https://github.com/login/device", | ||
// expires_in: 900, | ||
// interval: 5, | ||
// }; | ||
|
||
console.log("Open %s", verification.verification_uri); | ||
console.log("Enter code: %s", verification.user_code); | ||
}, | ||
}, | ||
}); | ||
|
||
const { | ||
data: { login }, | ||
} = await octokit.rest.users.getAuthenticated(); | ||
|
||
console.log("Hello, %s", login); | ||
|
||
return octokit; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { Select } from "https://deno.land/x/cliffy/prompt/select.ts"; | ||
import { Input } from "https://deno.land/x/cliffy/prompt/input.ts"; | ||
import { Toggle } from "https://deno.land/x/cliffy/prompt/toggle.ts"; | ||
|
||
let cache = {}; | ||
|
||
export async function download_repos(octokit) { | ||
let is_org = await Select.prompt({ | ||
message: "Where are these repos?", | ||
options: [ | ||
{value: 'org', name: 'Organization'}, | ||
{value: 'user', name: 'User'} | ||
], | ||
}) == 'org'; | ||
|
||
const name = await Input.prompt(`What is the ${is_org ? 'organization' : 'user'} name?`); | ||
|
||
let fetch_repos = true; | ||
let suggestions; | ||
|
||
if (cache[name]?.length > 0) { | ||
fetch_repos = await Toggle.prompt("I have recently fetched these repos. Should I fetch them again?"); | ||
suggestions = cache[name].map(v => { | ||
return v.name; | ||
}) | ||
} | ||
|
||
const reg = await Input.prompt({ | ||
message: `What would you like to search for?`, | ||
suggestions, | ||
list: suggestions !== undefined, | ||
}); | ||
|
||
let repos = await get_repos(octokit, is_org, name, reg); | ||
|
||
const req = { name: "run" }; | ||
const perm = await Deno.permissions.request(req); | ||
|
||
if (perm.state == "granted") { | ||
await Promise.all(repos.map(async (r) => { | ||
let dir_name = `./tmp/${r.full_name}`; | ||
|
||
const rm = Deno.run({ | ||
cmd: ["rm", "-rf", dir_name] | ||
}) | ||
|
||
await rm.status(); | ||
|
||
const clone = Deno.run({ | ||
cmd: ["git", "clone", r.clone_url, dir_name] | ||
}) | ||
|
||
return clone.status(); | ||
})) | ||
|
||
await Deno.permissions.revoke(req) | ||
} else { | ||
console.log('failed to download -- please grant permissions to run scripts') | ||
} | ||
|
||
return repos; | ||
} | ||
|
||
export async function delete_repos(octokit) { | ||
|
||
} | ||
|
||
async function get_repos(octokit, is_org, name, reg) { | ||
let err; | ||
|
||
let repos = await octokit.paginate(`GET /${is_org ? `orgs` : `users` }/{owner}/repos`, { | ||
owner: name, | ||
per_page: 100 | ||
}).catch(e => { | ||
console.log(e); | ||
return []; | ||
}) | ||
|
||
cache[name] = repos; | ||
|
||
if (typeof reg == "string") { | ||
reg = new RegExp(reg) | ||
} | ||
|
||
return repos.filter((v) => { | ||
return reg.test(v.name) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
let repos = ['kit-static-error', 'manga-reader']; | ||
|
||
await Promise.all(repos.map(async (r) => { | ||
const rm = Deno.run({ | ||
cmd: ["rm", "-rf", `./tmp/${r}`] | ||
}) | ||
|
||
await rm.status(); | ||
|
||
const clone = Deno.run({ | ||
cmd: ["git","clone",`https://github.com/DryCreations/${r}.git`, `./tmp/${r}`] | ||
}) | ||
|
||
return clone.status(); | ||
})) |