-
Notifications
You must be signed in to change notification settings - Fork 104
feat: Migrate repo labels to Gitee #969
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import React from 'react'; | ||
| import { Label } from '../../../../api/common'; | ||
|
|
||
| interface OpenDiggerLabelProps { | ||
| label: Label; | ||
| } | ||
|
|
||
| const OpenDiggerLabel: React.FC<OpenDiggerLabelProps> = ({ label }) => { | ||
| return ( | ||
| <a | ||
| id={`opendigger-label-${label.id}`} | ||
| className="project-label-item-box" | ||
| href="https://open-digger.cn" | ||
| target="_blank" | ||
| > | ||
| <div | ||
| className="project-label-item " | ||
| style={{ | ||
| whiteSpace: 'normal', | ||
| maxWidth: '100%', | ||
| }} | ||
| > | ||
| <img | ||
| style={{ | ||
| marginLeft: '-4px', | ||
| marginRight: '2px', | ||
| borderRadius: '50%', | ||
| verticalAlign: 'middle', | ||
| transform: 'translateY(-1px)', | ||
| }} | ||
| src={chrome.runtime.getURL('openDiggerLogo.png')} | ||
| width={16} | ||
| height={16} | ||
| /> | ||
| {label.name} | ||
| </div> | ||
| </a> | ||
| ); | ||
| }; | ||
|
|
||
| export default OpenDiggerLabel; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import features from '../../../../feature-manager'; | ||
| import { getRepoName, hasRepoContainerHeader, isPublicRepoWithMeta } from '../../../../helpers/get-gitee-repo-info'; | ||
| import { Label, RepoMeta, metaStore } from '../../../../api/common'; | ||
| import { createRoot } from 'react-dom/client'; | ||
| import OpenDiggerLabel from './gitee-OpenDiggerLabel'; | ||
|
|
||
| import React from 'react'; | ||
| import $ from 'jquery'; | ||
| import isGitee from '../../../../helpers/is-gitee'; | ||
| import { getPlatform } from '../../../../helpers/get-platform'; | ||
| const featureId = features.getFeatureID(import.meta.url); | ||
| let platform: string; | ||
| const getLabels = async (repoName: string) => { | ||
| const meta = (await metaStore.get(platform, repoName)) as RepoMeta; | ||
| return meta.labels?.filter((label) => { | ||
| return !(label.type.includes('-') && parseInt(label.type.split('-')[1]) > 0); | ||
| }); | ||
| }; | ||
|
|
||
| const renderTags = (labels: Label[]) => { | ||
| const defaultDiv = document.querySelector('.intro-list .default') as HTMLElement; | ||
| if (defaultDiv) { | ||
| defaultDiv.style.display = 'none'; | ||
| $('.mixed-label').css('display', 'block'); | ||
| } | ||
|
|
||
| let giteeTagContainer = $('.mixed-label'); | ||
| for (const label of labels) { | ||
| const id = `opendigger-label-${label.id}`; | ||
| // if the tag already exists, skip | ||
| if (document.getElementById(id)) { | ||
| continue; | ||
| } | ||
| const labelElement = document.createElement('a'); | ||
|
||
| createRoot(labelElement).render(<OpenDiggerLabel label={label} />); | ||
| giteeTagContainer.append(labelElement); | ||
| } | ||
| }; | ||
|
|
||
| const init = async (): Promise<void> => { | ||
| platform = getPlatform(); | ||
| const repoName = getRepoName(); | ||
| const labels = await getLabels(repoName); | ||
|
|
||
| if (labels && labels.length > 0) { | ||
| renderTags(labels); | ||
| } | ||
| }; | ||
|
|
||
| features.add(featureId, { | ||
| asLongAs: [isGitee, isPublicRepoWithMeta, hasRepoContainerHeader], | ||
| awaitDomReady: true, | ||
| init, | ||
| }); | ||

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.
The tag height of Gitee is slightly smaller than that of GitHub. It feels better to make this picture smaller.
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.
ok