Skip to content

Commit 2508991

Browse files
committed
Add basic coverage badge
1 parent 76ceb71 commit 2508991

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/coverage.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,32 @@
7575
top: -1px;
7676
}
7777

78+
.qlty-diff-badge {
79+
display: inline-block;
80+
vertical-align: middle;
81+
border-radius: 6px;
82+
color: #333;
83+
font-size: 12px;
84+
line-height: 1.5;
85+
border: 1px solid rgba(0, 0, 0, 0.1);
86+
padding: 6px;
87+
88+
.qlty-icon {
89+
margin-right: 0;
90+
width: 18px;
91+
height: 18px;
92+
}
93+
94+
&.qlty-diff-badge-pr {
95+
order: 2;
96+
padding: 4px;
97+
.qlty-icon {
98+
width: 16px;
99+
height: 16px;
100+
}
101+
}
102+
}
103+
78104
.qlty-toast .qlty-icon {
79105
display: inline-block;
80106
background-color: #fff;

src/github.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,16 @@ function tryInjectDiffPullRequestUIElement(
7070
});
7171

7272
console.log("[qlty] injected diff PR UI");
73+
addPRPageBadge();
7374
rootElement.classList.add("qlty-diff-ui");
7475
}
7576

77+
function addPRPageBadge(): void {
78+
const badge = createBadge("pr");
79+
if (!badge) return;
80+
document.querySelector(".gh-header-actions")?.prepend(badge);
81+
}
82+
7683
function tryInjectDiffCommitUI(): void {
7784
const rootElement = document.getElementById("diff-content-parent");
7885
if (!rootElement) return;
@@ -103,9 +110,27 @@ function tryInjectDiffCommitUI(): void {
103110
});
104111

105112
console.log("[qlty] injected diff commit UI");
113+
addDiffPageBadge();
106114
rootElement.classList.add("qlty-diff-ui");
107115
}
108116

117+
function addDiffPageBadge(): void {
118+
const badge = createBadge("commit");
119+
if (!badge) return;
120+
document.querySelector("[data-component=PH_Actions] div")?.prepend(badge);
121+
}
122+
123+
function createBadge(type: "pr" | "commit"): HTMLDivElement | null {
124+
if (document.querySelector(".qlty-diff-badge")) {
125+
return null;
126+
}
127+
const badge = document.createElement("div");
128+
badge.classList.add("qlty-diff-badge");
129+
badge.classList.add(`qlty-diff-badge-${type}`);
130+
badge.appendChild(document.createElement("div")).classList.add("qlty-icon");
131+
return badge;
132+
}
133+
109134
async function injectIntoFileContainer(
110135
container: Element,
111136
path: string | null,

0 commit comments

Comments
 (0)