-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
[WIP] Add a GUI #59
Open
CapriciousRebel
wants to merge
40
commits into
main
Choose a base branch
from
add-gui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[WIP] Add a GUI #59
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
fc3d95a
[Feature]: Add a POC for the web app
CapriciousRebel 6f41c1e
[Feature]: Add purge configuration to remove unused tailwindcss classes
CapriciousRebel c3e725e
\n issue fixed
rosekamallove 57863d2
[Feature]: Add express server to expose an api
CapriciousRebel 7e45b9d
Rebase with remote
CapriciousRebel eb59c43
[Feat]: Add input command box
CapriciousRebel caad47a
[Refactor]: Remove unused repos
CapriciousRebel f6d2c4e
[Refactor]: Update CSS
CapriciousRebel 0ec8e68
[Refactor]: Remove unnecessary files and config
CapriciousRebel 091e52d
Remove DS_Store file
CapriciousRebel c310dda
Add DSStore to gitignore
CapriciousRebel 48c02af
add doubt comments
CapriciousRebel 274d813
add sample env file and update setup instructions in readme
CapriciousRebel 127c05f
[Fix]: border issue
CapriciousRebel 1eb0712
center the circles in the table
CapriciousRebel 4af652b
Add a status indicator
CapriciousRebel 6f68b03
Add eslint disable for magic numbers
CapriciousRebel 365ce21
Add newline to end of files
CapriciousRebel df5fd26
Merge branch 'main' into add-gui
CapriciousRebel e65d0ed
Fix merge errors
CapriciousRebel c1e3a14
Update to align with the format of the latest main branch
CapriciousRebel 89c44e4
[Feature]: Add table clear feature before loading new table
CapriciousRebel 8384471
[Fix]: Seperate the styles into another file
CapriciousRebel da8ca7e
[Fix]: apply formatting on index.html
CapriciousRebel b040819
[Fix]: remove hardcoded url
CapriciousRebel 1d2f06a
[Fix]: remove unnecessary implicit string conversion
CapriciousRebel 84ff4d8
[Fix]: remove unnecessary implicit string conversion
CapriciousRebel 124f9f7
[Fix]: add GITHUB_TOKEN along with GH_TOKEN
CapriciousRebel 9cd20ba
[Refactor]: remove unnecessary forEach loop
CapriciousRebel bf53a70
[Refactor]: generateGui
CapriciousRebel e24218a
Merge branch 'main' into add-gui
CapriciousRebel d7b8e79
[Refactor]: utils file
CapriciousRebel 295eac2
[Revert]: remove DS_Store from gitignore
CapriciousRebel ebe3900
[Refactor]: conversion of table output to sting
CapriciousRebel 5e3df41
[Refactor]: remove unnecessary branch from detail.js
CapriciousRebel 0a87131
[Refactor]: server/app.js
CapriciousRebel bf7726c
[Fix, Refactor]: server import fix and better syntax to check for array
CapriciousRebel d88896d
[Refactor]: better export syntax
CapriciousRebel 568e7e0
[Refactor]: remove css variables
CapriciousRebel b57f665
[Fix, Refactor, Feature]: fix token issue, refactor css file, add err…
CapriciousRebel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,3 @@ | ||
GH_TOKEN=<Your Github Token> | ||
port=3000 | ||
XDG_CONFIG_HOME= |
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
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
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
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
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,20 @@ | ||
'use strict'; | ||
|
||
const express = require('express'); | ||
const { executeCommand } = require('./controllers'); | ||
const path = require('path'); | ||
const open = require('open'); | ||
|
||
module.exports = function server() { | ||
const app = express(); | ||
const { port } = process.env; | ||
app.use(express.json()); | ||
app.use(express.urlencoded({ extended: true })); | ||
app.use('/', express.static(path.join(__dirname, '../static'))); | ||
app.post('/command', executeCommand); | ||
app.listen(port, () => { | ||
console.log(`Api is listening on port ${port}`); | ||
console.log(`View the gui on: http://localhost:${port}/`); | ||
}); | ||
open(`http://localhost:${port}/`); | ||
}; |
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,194 @@ | ||||||||||||||
/* eslint-disable no-magic-numbers */ | ||||||||||||||
|
||||||||||||||
'use strict'; | ||||||||||||||
|
||||||||||||||
const { StatusCodes } = require('http-status-codes'); | ||||||||||||||
|
||||||||||||||
const parse = require('yargs-parser'); | ||||||||||||||
const { | ||||||||||||||
listMetrics, | ||||||||||||||
getRepositories, | ||||||||||||||
generateDetailTable, | ||||||||||||||
generateGui, | ||||||||||||||
} = require('../utils'); | ||||||||||||||
|
||||||||||||||
const getMetrics = require('../metrics'); | ||||||||||||||
|
||||||||||||||
// Metric names and their extraction method to be used on the query result (Order is preserved) | ||||||||||||||
const metricNames = [ | ||||||||||||||
'Repository', | ||||||||||||||
'isFork', | ||||||||||||||
'Access', | ||||||||||||||
'IssuesEnabled', | ||||||||||||||
'ProjectsEnabled', | ||||||||||||||
'WikiEnabled', | ||||||||||||||
'AllowsForking', | ||||||||||||||
'Archived', | ||||||||||||||
'AutoMergeAllowed', | ||||||||||||||
'BlankIssuesEnabled', | ||||||||||||||
'SecurityPolicyEnabled', | ||||||||||||||
'License', | ||||||||||||||
'MergeStrategies', | ||||||||||||||
'DeleteOnMerge', | ||||||||||||||
'HasStarred', | ||||||||||||||
'Subscription', | ||||||||||||||
'DefBranch', | ||||||||||||||
'AllowsForcePushes', | ||||||||||||||
'AllowsDeletions', | ||||||||||||||
'DismissesStaleReviews', | ||||||||||||||
'ReqApprovingReviewCount', | ||||||||||||||
'ReqApprovingReviews', | ||||||||||||||
'ReqCodeOwnerReviews', | ||||||||||||||
'ReqConversationResolution', | ||||||||||||||
'isPrivate', | ||||||||||||||
]; | ||||||||||||||
|
||||||||||||||
const generateQuery = (endCursor, { | ||||||||||||||
f, | ||||||||||||||
}) => { | ||||||||||||||
let showForks = false; | ||||||||||||||
let showSources = true; | ||||||||||||||
let showPrivate = false; | ||||||||||||||
let showPublic = true; | ||||||||||||||
if (Array.isArray(f)) { | ||||||||||||||
showForks = f.includes('forks'); | ||||||||||||||
showSources = f.includes('sources'); | ||||||||||||||
showPrivate = f.includes('private'); | ||||||||||||||
showPublic = f.includes('public'); | ||||||||||||||
} | ||||||||||||||
return ( | ||||||||||||||
`query { | ||||||||||||||
viewer { | ||||||||||||||
repositories( | ||||||||||||||
first: 100 | ||||||||||||||
affiliations: [OWNER, ORGANIZATION_MEMBER, COLLABORATOR] | ||||||||||||||
${endCursor ? `after: "${endCursor}"` : ''} | ||||||||||||||
${showForks === showSources ? '' : showForks ? 'isFork: true' : 'isFork: false'} | ||||||||||||||
${showPrivate === showPublic ? '' : showPublic ? 'privacy: PUBLIC' : 'privacy: PRIVATE'} | ||||||||||||||
) { | ||||||||||||||
totalCount | ||||||||||||||
pageInfo { | ||||||||||||||
endCursor | ||||||||||||||
hasNextPage | ||||||||||||||
} | ||||||||||||||
nodes { | ||||||||||||||
name | ||||||||||||||
nameWithOwner | ||||||||||||||
defaultBranchRef { | ||||||||||||||
name | ||||||||||||||
branchProtectionRule { | ||||||||||||||
allowsForcePushes | ||||||||||||||
allowsDeletions | ||||||||||||||
dismissesStaleReviews | ||||||||||||||
requiredApprovingReviewCount | ||||||||||||||
requiresApprovingReviews | ||||||||||||||
requiresCodeOwnerReviews | ||||||||||||||
requiresConversationResolution | ||||||||||||||
restrictsPushes | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
deleteBranchOnMerge | ||||||||||||||
hasIssuesEnabled | ||||||||||||||
hasProjectsEnabled | ||||||||||||||
hasWikiEnabled | ||||||||||||||
forkingAllowed | ||||||||||||||
isArchived | ||||||||||||||
autoMergeAllowed | ||||||||||||||
isBlankIssuesEnabled | ||||||||||||||
isFork | ||||||||||||||
isPrivate | ||||||||||||||
isSecurityPolicyEnabled | ||||||||||||||
isTemplate | ||||||||||||||
licenseInfo { | ||||||||||||||
name | ||||||||||||||
} | ||||||||||||||
mergeCommitAllowed | ||||||||||||||
owner { | ||||||||||||||
login | ||||||||||||||
} | ||||||||||||||
rebaseMergeAllowed | ||||||||||||||
squashMergeAllowed | ||||||||||||||
createdAt | ||||||||||||||
updatedAt | ||||||||||||||
pushedAt | ||||||||||||||
viewerHasStarred | ||||||||||||||
viewerPermission | ||||||||||||||
viewerSubscription | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
rateLimit { | ||||||||||||||
cost | ||||||||||||||
remaining | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
`); | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
/* | ||||||||||||||
* DOUBT: Copy-Pasted this function here as I was having issues with importing the function | ||||||||||||||
* from src/commands/detail.js | ||||||||||||||
*/ | ||||||||||||||
const detail = async (flags) => { | ||||||||||||||
Comment on lines
+128
to
+132
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm still not sure what the issue would be - what happens if you |
||||||||||||||
if (flags.m) { | ||||||||||||||
return listMetrics(getMetrics(metricNames)); | ||||||||||||||
} | ||||||||||||||
let metrics; | ||||||||||||||
if (flags.p?.length > 0) { | ||||||||||||||
metrics = getMetrics([ | ||||||||||||||
'Repository', | ||||||||||||||
'isFork', | ||||||||||||||
'isPrivate', | ||||||||||||||
...metricNames.filter((name) => flags.p.includes(name)), | ||||||||||||||
]); | ||||||||||||||
} else { | ||||||||||||||
metrics = getMetrics(metricNames); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// Additional Filter on repos | ||||||||||||||
let filter; | ||||||||||||||
if (flags.f?.length === 1 && flags.f[0] === 'templates') { | ||||||||||||||
filter = (repo) => repo.isTemplate; | ||||||||||||||
} | ||||||||||||||
// Get all repositories | ||||||||||||||
const { repositories } = await getRepositories(generateQuery, flags, filter); | ||||||||||||||
if (!flags.s) { | ||||||||||||||
repositories.sort((a, b) => new Date(b.updatedAt) - new Date(a.updatedAt)); | ||||||||||||||
} | ||||||||||||||
// Generate output table | ||||||||||||||
const table = generateDetailTable(metrics, repositories, { | ||||||||||||||
actual: flags.actual, all: flags.all, goodness: flags.goodness, sort: flags.s, unactionable: flags.unactionable, | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
}); | ||||||||||||||
|
||||||||||||||
return table || null; | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
const executeCommand = async (req, res) => { | ||||||||||||||
const { command } = req.body; | ||||||||||||||
const argv = parse(command); | ||||||||||||||
argv.goodness = true; | ||||||||||||||
|
||||||||||||||
if (!argv.token) { | ||||||||||||||
// token not present, so check positional argument to check if GH_TOKEN or GITHUB_TOKEN is present | ||||||||||||||
argv._.forEach((element) => { | ||||||||||||||
const [key, val] = element.split('='); | ||||||||||||||
if (key === 'GH_TOKEN' || key === 'GITHUB_TOKEN') { | ||||||||||||||
argv.token = val; | ||||||||||||||
} | ||||||||||||||
}); | ||||||||||||||
if (!argv.token) { | ||||||||||||||
// no token provided in frontend, hence return 403 | ||||||||||||||
return res.status(StatusCodes.FORBIDDEN).json({ | ||||||||||||||
msg: 'env variable GH_TOKEN or GITHUB_TOKEN, or `--token` argument, not found.', | ||||||||||||||
success: 0, | ||||||||||||||
}); | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
let output = await detail(argv); | ||||||||||||||
output = generateGui(output); | ||||||||||||||
return res.status(StatusCodes.OK).json({ output }); | ||||||||||||||
}; | ||||||||||||||
|
||||||||||||||
module.exports = { | ||||||||||||||
executeCommand, | ||||||||||||||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like this file contains a lot of copied code from elsewhere in the repo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is the code from the
details.js
file. Kindly consider this commit as an intermediate step. I was having some trouble with the exports(for some reason importing thedetail
function gave errors, saying detail wasn't a function). So I just copy-pasted the code instead to make things work for the time being. I will fix this in a future commit and perhaps squash this commit.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good :-) just calling it out so it's not forgotten.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still a doubt for me, could you probably suggest me a fix for this? I'm not sure why importing from detail.js is not working. Perhaps there is some issue with express js? Not really sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure either. Can you restore the import, and i'll try it locally?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's address this issue at the very end of this PR, once we have everything in working order.