Skip to content

Commit

Permalink
feat: merge mode support orgs repo
Browse files Browse the repository at this point in the history
  • Loading branch information
baiwusanyu-c committed Apr 19, 2023
1 parent c67f5c4 commit 3038596
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 30 deletions.
70 changes: 70 additions & 0 deletions packages/extension/assets/styles/scroll.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* WebKit浏览器滚动条整体样式 */
::-webkit-scrollbar {
width: 6px;
height: 6px;
background-color: transparent;
}

/* WebKit浏览器滚动条滑块样式 */
::-webkit-scrollbar-thumb {
border-radius: 4px;
background-color: #3ccaa4;
}

/* 其他浏览器滚动条整体样式 */
* {
scrollbar-width: thin;
scrollbar-color: #3ccaa4 transparent;
}

/* 其他浏览器滚动条滑块样式 */
*::-webkit-scrollbar-thumb {
border-radius: 4px;
background-color: #3ccaa4;
}

/* IE11滚动条样式 */
* {
-ms-overflow-style: none;
}

/* Firefox滚动条样式 */
* {
scrollbar-width: thin;
scrollbar-color: #3ccaa4 transparent;
}

*::-moz-scrollbar-thumb {
border-radius: 4px;
background-color: #3ccaa4;
}

/* Safari滚动条样式 */
*::-webkit-scrollbar-corner {
background-color: transparent;
}

/* 滚动条hover状态下样式 */
*::-webkit-scrollbar-thumb:hover {
background-color: #1b8e7f;
}

/* 滚动条拖动状态下样式 */
*::-webkit-scrollbar-thumb:active {
background-color: #006d5b;
}

/* 滚动条聚焦状态下样式 */
*::-webkit-scrollbar-thumb:focus {
outline: 1px solid #3ccaa4;
}

/* 滚动条轨道样式 */
*::-webkit-scrollbar-track {
background-color: transparent;
}

/* 滚动条轨道hover状态下样式 */
*::-webkit-scrollbar-track:hover {
background-color: rgba(60, 202, 164, 0.3);
}
65 changes: 44 additions & 21 deletions packages/extension/chrome-option/components/RepoList.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Button, Input, Spin, Tooltip } from 'antd'
import { getAllRepo, getIssuesPR } from '@pr-checker/fetchGit'
import { Input, Spin, Tooltip } from 'antd'
import { getAllOrgsRepo, getAllRepo, getIssuesPR, getOrgsInfo } from '@pr-checker/fetchGit'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { useThrottleFn } from 'ahooks'
import { createRunList } from '@pr-checker/utils'
// TODO all select handle
interface IRepoListProps {
opType: string
Expand Down Expand Up @@ -58,26 +59,39 @@ export const RepoList = (props: IRepoListProps) => {
// merge 模式 我们只获取仓库信息
if (opType === 'merge' && token) {
getAllRepo(token).then((res) => {
const hasIssuesRepo = res.filter(val => val.open_issues_count > 0 && !val.fork)
const repos = new Map<string, IRepoWithPRs>()
hasIssuesRepo.forEach((val) => {
const repoName = val.url.split('/').pop()!
const repoUName = val.url.split('repos/').pop()!
const repoURL = val.url
repos.set(repoURL, { name: repoName, url: repoURL, uname: repoUName, pullRequests: [val] })
})
// 将 map 转成数组,并设置到 state 里
const resRepo = [...repos.values()]
setRepoList(resRepo)
repoListCache.current = resRepo
resRepo.length > 0 && onSelect(resRepo[0])
handleRepoInfoByMerge(res)
}).finally(() => {
setLoading(false)
})
getOrgsInfo(token).then(async(res) => {
await Promise.all(createRunList(res.length, async(i: number) => {
setLoading(true)
const repo = await getAllOrgsRepo(token, res[i].login)
handleRepoInfoByMerge(repo)
}))
}).finally(() => {
setLoading(false)
})
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [token, userName, opType])

function handleRepoInfoByMerge(res: Array<any>) {
const hasIssuesRepo = res.filter(val => !val.fork)
const repos = new Map<string, IRepoWithPRs>()
hasIssuesRepo.forEach((val) => {
const repoName = val.url.split('/').pop()!
const repoUName = val.url.split('repos/').pop()!
const repoURL = val.url
repos.set(repoURL, { name: repoName, url: repoURL, uname: repoUName, pullRequests: [val] })
})
// 将 map 转成数组,并设置到 state 里
const resRepo = [...repos.values()]
repoListCache.current = resRepo.concat(repoList)
setRepoList([...resRepo.concat(repoList)])
resRepo.length > 0 && onSelect(resRepo[0])
}

const [activeIndex, setActiveIndex] = useState(0)
const handleClick = useCallback((index: number) => {
setActiveIndex(index)
Expand All @@ -94,8 +108,15 @@ export const RepoList = (props: IRepoListProps) => {
onClick={() => handleClick(index)}
>
{/* <Avatar size={20} className="mr-2" shape="square">{value[0]}</Avatar> */}
<span style={{ fontSize: '14px' }} className="text-bold">
{repo.name}
<span style={{
fontSize: '14px',
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
}}
className="text-bold"
>
{repo.name }
</span>
</li>
</Tooltip>
Expand All @@ -121,11 +142,13 @@ export const RepoList = (props: IRepoListProps) => {
return (
<div id="pr_checker_repo_list">
<Search placeholder="Input repo name" className="mb-4 !dark:bg-gray-7" onChange={run} allowClear />
<Button type="primary" className="mb-4 w-full" >
{/* <Button type="primary" className="mb-4 w-full" >
{ `${props.opType || 'rebase'} all`}
</Button>
<ul className="list-none p-0 min-w-1 border-1"
style={loading ? { display: 'flex', justifyContent: 'center' } : {}}
</Button> */}
<ul className="list-none p-0 min-w-1 border-1 over-y"
style={loading
? { display: 'flex', justifyContent: 'center', maxHeight: 'calc(100vh - 128px)' }
: { maxHeight: 'calc(100vh - 128px)' }}
>
<Spin spinning={loading} tip="Loading..." className="my-4" />
{repoListEl}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const PrList = (props: PrListProps) => {

const compareBranchToUpdate = useCallback(
async(number: number, repo: string, res: DataType) => {
// TODO:或许可以更换接口?
const prInfo = await getPRDetail(props.token, repo, number)
res.author = prInfo.user.login
if (prInfo.mergeable_state === 'dirty') {
Expand Down Expand Up @@ -99,11 +98,10 @@ export const PrList = (props: PrListProps) => {
useEffect(() => {
setLoading(true)
setTableData([])
if (props.repoInfo.pullRequests.length > 0) {
if (props.repoInfo.pullRequests.length > 0)
handleTableData(props.repoInfo.pullRequests, props.repoInfo.uname)
} else {
else
setTimeout(() => setLoading(false), 300)
}
}, [props.repoInfo.uname, props.repoInfo.pullRequests, handleTableData])

const { search } = useSearch(tableDataCache, setTableData)
Expand Down
1 change: 1 addition & 0 deletions packages/extension/chrome-option/main.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ReactDOM from 'react-dom/client'
import { OptionPage } from './view/OptionPage'
import 'antd/dist/reset.css'
import '../assets/styles/scroll.css'
import 'uno.css'
ReactDOM.createRoot(document.getElementById('app') as HTMLElement).render(
<OptionPage />,
Expand Down
3 changes: 3 additions & 0 deletions packages/extension/unocss.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export default defineConfig({
}),
presetTypography(),
],
rules: [
['over-y', { 'overflow-y': 'auto' }],
],
transformers: [
transformerDirectives(),
transformerVariantGroup(),
Expand Down
24 changes: 19 additions & 5 deletions packages/fetch-git/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,34 @@ export async function getIssuesPR(token: string, username: string) {
}

export async function getAllRepo(token: string) {
/* const res = await request(`${baseUrl}/user/repos`, {
const res = await request(`${baseUrl}/user/repos`, {
method: 'GET',
token,
params: {
type: 'owner',
per_page: 1000,
},
}) */
// TODO 组织?
const res = await request(`${baseUrl}/orgs/Be-UI/repos`, {
})
return res
}

export async function getOrgsInfo(token: string) {
const res = await request(`${baseUrl}/user/orgs`, {
method: 'GET',
token,
params: {
type: 'owner',
per_page: 1000,
},
})
return res
}

export async function getAllOrgsRepo(token: string, orgName: string) {
const res = await request(`${baseUrl}/orgs/${orgName}/repos`, {
method: 'GET',
token,
params: {
// q: `is:pr is:open author:${username}`,
per_page: 1000,
},
})
Expand Down

0 comments on commit 3038596

Please sign in to comment.