Skip to content
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

collect-commit-comments - Show all commit comments in the comment section #7349

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions source/features/collect-commit-comments.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.rgh-comment-header {
display: flex;
align-items: center;
padding-left: 16px;
padding-top: 8px;
padding-bottom: 8px;
color: var(--fgColor-muted, var(--color-fg-muted));
border-bottom: 1px solid var(--borderColor-default, var(--color-border-default));
border-top-left-radius: 6px;
border-top-right-radius: 6px;
background-color: var(--bgColor-muted, var(--color-canvas-subtle));
}

.rgh-comment-header-bolt {
color: #FFFF;
align-items: center;
}
23 changes: 23 additions & 0 deletions source/features/collect-commit-comments.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
query GetCommentsFromCommit($owner:String!, $name:String!, $commit:String) {
repository(owner:$owner, name:$name) {
name,
object(expression:$commit) {
... on Commit {
message,
comments(first:100) {
nodes {
author {
avatarUrl,
login
},
authorAssociation,
bodyHTML,
url,
position,
path
}
}
}
}
}
}
69 changes: 69 additions & 0 deletions source/features/collect-commit-comments.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import './collect-commit-comments.css';
import * as pageDetect from 'github-url-detection';

Check failure on line 2 in source/features/collect-commit-comments.tsx

View workflow job for this annotation

GitHub Actions / Lint

There should be at least one empty line between import groups
import features from '../feature-manager.js';
import observe from '../helpers/selector-observer.js';

Check failure on line 4 in source/features/collect-commit-comments.tsx

View workflow job for this annotation

GitHub Actions / Lint

There should be at least one empty line between import groups
import React from 'dom-chef';

Check failure on line 5 in source/features/collect-commit-comments.tsx

View workflow job for this annotation

GitHub Actions / Lint

There should be at least one empty line between import groups

Check failure on line 5 in source/features/collect-commit-comments.tsx

View workflow job for this annotation

GitHub Actions / Lint

`dom-chef` import should occur before import of `../feature-manager.js`
import api from '../github-helpers/api.js';
import GetCommentsFromCommit from './collect-commit-comments.gql';

Check failure on line 7 in source/features/collect-commit-comments.tsx

View workflow job for this annotation

GitHub Actions / Lint

There should be at least one empty line between import groups
import { CachedFunction } from 'webext-storage-cache';

Check failure on line 8 in source/features/collect-commit-comments.tsx

View workflow job for this annotation

GitHub Actions / Lint

`webext-storage-cache` import should occur before import of `../feature-manager.js`

Check failure on line 8 in source/features/collect-commit-comments.tsx

View workflow job for this annotation

GitHub Actions / Lint

There should be no space after '{'.

Check failure on line 8 in source/features/collect-commit-comments.tsx

View workflow job for this annotation

GitHub Actions / Lint

There should be no space before '}'.

const getCommitComments = new CachedFunction('get-comments', {
async updater(commit: string): Promise<any> {
const { repository: { object: { comments } } } = await api.v4(GetCommentsFromCommit, {

Check failure on line 12 in source/features/collect-commit-comments.tsx

View workflow job for this annotation

GitHub Actions / Lint

There should be no space after '{'.

Check failure on line 12 in source/features/collect-commit-comments.tsx

View workflow job for this annotation

GitHub Actions / Lint

There should be no space after '{'.
variables: {
commit
}
});

return comments;
}
});

async function append(element: HTMLElement): Promise<void> {
const commitSha = location.pathname.split('/').pop()!;
const comments = await getCommitComments.get(commitSha);
console.log(comments.nodes);
for (let commentsKey in comments.nodes) {
const comment = comments.nodes[commentsKey];
if (comment.position === null) continue;
const author = comment.author;
const body = comment.bodyHTML;
const url = comment.url;
const pos = comment.position;
const path = comment.path;

element.append(
<div className={'js-comment-container TimelineItem d-block'}>
<a className={'avatar-parent-child TimelineItem-avatar d-none d-md-block'}>
<img className={'avatar rounded-2 avatar-user'} src={author.avatarUrl + '?s=80&v=4'} alt={author.login}
width={40} height={40} />
</a>
<div
className={'timeline-comment-group js-minimizable-comment-group js-targetable-element my-0 comment previewable-edit js-task-list-container js-comment timeline-comment timeline-comment--caret ml-n3 js-minimize-container unminimized-comment'}>
<div className={'rgh-comment-header clearfix d-flex'}>
<div>
<b className={'rgh-comment-header-bolt'}>{author.login}</b> commented on <a href={url}>line {pos}</a> in file {path}</div>
</div>
<div
className={'comment-body markdown-body js-comment-body soft-wrap css-overflow-wrap-anywhere user-select-contain d-block'}>
<div dangerouslySetInnerHTML={{ __html: body }}></div>
</div>
</div>
</div>
);
}


}

async function init(signal: AbortSignal): Promise<void> {
observe('div#comments', append, { signal });
}

void features.add(import.meta.url, {
include: [
pageDetect.isCommit
],
init
});

Check failure on line 69 in source/features/collect-commit-comments.tsx

View workflow job for this annotation

GitHub Actions / TestURLs

Every new or edited feature must be tested manually before merging. To help testing, we're progressively adding test URLs in each feature. You can find or create a test URL: - on our sandbox repo: https://github.com/refined-github/sandbox - on previous PRs for this feature The section must be appended to each .tsx file: /* Test URLs: https://github.com/a/REAL/url/here https://github.com/another/REAL/url/here */
1 change: 1 addition & 0 deletions source/refined-github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,4 @@ import './features/fix-no-pr-search.js';
import './features/clean-readme-url.js';
import './features/pr-notification-link.js';
import './features/click-outside-modal.js';
import './features/collect-commit-comments.js';