-
Notifications
You must be signed in to change notification settings - Fork 1
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
Convert badge-setter and html-generator to JavaScript #59
Merged
coorasse
merged 16 commits into
feature/v2
from
devin/1737468209-convert-badge-and-html-to-js
Jan 22, 2025
Merged
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
7178011
Convert badge-setter and html-generator to JavaScript with JSDoc comm…
devin-ai-integration[bot] fe7546a
Convert badge-setter and html-generator test files to JavaScript
devin-ai-integration[bot] a743c74
Fix factories import, remove JSDoc comments, improve coverage for htm…
devin-ai-integration[bot] c458975
fix: update HTML structure and subdescription format in html-generato…
devin-ai-integration[bot] ef8909f
fix: update HTML structure to match test expectations
devin-ai-integration[bot] 5e44da5
fix: update subdescription to use id instead of number
devin-ai-integration[bot] aacf272
fix: Update html-generator.js DOM structure to match test expectations
devin-ai-integration[bot] 653641a
fix: Update subdescription to use number instead of id
devin-ai-integration[bot] f1b1150
fix: Update DOM structure to match integration test expectations
devin-ai-integration[bot] e73f98b
fix: Add pr-link class to match integration test expectations
devin-ai-integration[bot] f2f95c5
fix: Simplify link structure to match integration test expectations
devin-ai-integration[bot] a087e0d
fix: Move subdescription into secondRow div to match test expectations
devin-ai-integration[bot] b76b7c8
fix: Remove JSDoc comments as requested in PR feedback
devin-ai-integration[bot] 93ae125
fix: Simplify DOM structure and use textContent for subdescription
devin-ai-integration[bot] 5398224
fix: Update test initialization order to ensure data is ready before …
devin-ai-integration[bot] 0978ae5
Fix
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
12 changes: 8 additions & 4 deletions
12
src/js/services/badge-setter.test.ts → src/js/services/badge-setter.test.js
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,120 @@ | ||
/** | ||
* @typedef {import('../static/types').CounterConfig} CounterConfig | ||
* @typedef {import('../static/types').PullRequest} PullRequest | ||
* @typedef {import('../static/types').PullRequestRecord} PullRequestRecord | ||
* @typedef {import('../static/types').PullRequestRecordKey} PullRequestRecordKey | ||
*/ | ||
|
||
import { recordKeysTranslations, extensionID } from '../static/constants.js'; | ||
|
||
const HTMLGenerator = () => { | ||
/** | ||
* @param {PullRequestRecord} record | ||
* @param {CounterConfig} counter | ||
* @returns {HTMLDivElement} | ||
*/ | ||
const generate = (record, counter) => { | ||
const topLevelDiv = document.createElement('div'); | ||
topLevelDiv.classList.add('pull-requests-loaded'); | ||
|
||
for (const key of Object.keys(record)) { | ||
if (record[key].length === 0) continue; | ||
const lessRelevant = !counter[key]; | ||
|
||
const titleP = document.createElement('h5'); | ||
titleP.textContent = recordKeysTranslations[key]; | ||
titleP.classList.add('title'); | ||
if (lessRelevant) titleP.classList.add('less-relevant-group'); | ||
topLevelDiv.appendChild(titleP); | ||
|
||
topLevelDiv.appendChild(generateLinkStructure(record[key], lessRelevant)); | ||
} | ||
|
||
if (topLevelDiv.children.length === 0) { | ||
const titleP = document.createElement('p'); | ||
titleP.textContent = 'Nothing to do'; | ||
titleP.classList.add('title'); | ||
topLevelDiv.classList.remove('pull-requests-loaded'); | ||
topLevelDiv.appendChild(titleP); | ||
topLevelDiv.appendChild(generateNoContent()); | ||
} | ||
|
||
return topLevelDiv; | ||
}; | ||
|
||
/** | ||
* @param {PullRequest[]} pullRequests | ||
* @param {boolean} lessRelevant | ||
* @returns {HTMLDivElement} | ||
*/ | ||
const generateLinkStructure = (pullRequests, lessRelevant) => { | ||
const groupLevelDiv = document.createElement('div'); | ||
groupLevelDiv.classList.add('group-container'); | ||
if (lessRelevant) groupLevelDiv.classList.add('less-relevant-group'); | ||
|
||
for (const PullRequest of pullRequests) { | ||
const pullRequestDiv = document.createElement('div'); | ||
const firstRow = document.createElement('div'); | ||
const secondRow = document.createElement('div'); | ||
pullRequestDiv.appendChild(firstRow); | ||
pullRequestDiv.appendChild(secondRow); | ||
|
||
const repoUrl = document.createElement('a'); | ||
repoUrl.appendChild(document.createTextNode(PullRequest.ownerAndName)); | ||
repoUrl.href = PullRequest.repositoryUrl; | ||
repoUrl.target = '_blank'; | ||
firstRow.appendChild(repoUrl); | ||
|
||
firstRow.appendChild(generatePullRequestLink(PullRequest)); | ||
secondRow.appendChild(generateSubDescription(PullRequest)); | ||
|
||
pullRequestDiv.classList.add('link-container'); | ||
groupLevelDiv.appendChild(pullRequestDiv); | ||
} | ||
|
||
return groupLevelDiv; | ||
}; | ||
|
||
/** | ||
* @returns {HTMLDivElement} | ||
*/ | ||
const generateNoContent = () => { | ||
const noContentDiv = document.createElement('div'); | ||
noContentDiv.classList.add('group-container'); | ||
const p1 = document.createElement('p'); | ||
const p2 = document.createElement('p'); | ||
p1.textContent = 'Seems like you are a good coworker :)'; | ||
const link = `<a href="chrome-extension://${extensionID}/options.html" target="_blank" class="link-in-text">options </a>`; | ||
p2.innerHTML = `Or you configured the extension wrong. Have a look the ${link} to verify your configuration.`; | ||
noContentDiv.appendChild(p1); | ||
noContentDiv.appendChild(p2); | ||
return noContentDiv; | ||
}; | ||
|
||
/** | ||
* @param {PullRequest} PullRequest | ||
* @returns {HTMLAnchorElement} | ||
*/ | ||
const generatePullRequestLink = (PullRequest) => { | ||
const link = document.createElement('a'); | ||
link.appendChild(document.createTextNode(PullRequest.title)); | ||
link.href = PullRequest.htmlUrl; | ||
link.target = '_blank'; | ||
return link; | ||
}; | ||
|
||
/** | ||
* @param {PullRequest} PullRequest | ||
* @returns {HTMLParagraphElement} | ||
*/ | ||
const generateSubDescription = (PullRequest) => { | ||
const subDescriptionP = document.createElement('p'); | ||
subDescriptionP.classList.add('subdescription'); | ||
subDescriptionP.appendChild(document.createTextNode(`#${PullRequest.number} opened ${Math.floor(PullRequest.ageInDays)} days ago by ${PullRequest.author}`)); | ||
return subDescriptionP; | ||
}; | ||
|
||
return { generate }; | ||
}; | ||
|
||
export default HTMLGenerator; |
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
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.
don't use jsdoc. remove them everywhere. remember this