rename branchcommits

git4refactor
filip mertens 7 months ago
parent 5c0a0a610f
commit 59ac71f571
  1. 4
      apps/remix-ide/src/app.js
  2. 13
      apps/remix-ide/src/app/files/dgitProvider.ts
  3. 30
      libs/remix-ui/git/src/components/panels/branches/branchedetails.tsx
  4. 32
      libs/remix-ui/git/src/lib/gitactions.ts
  5. 2
      libs/remix-ui/git/src/state/context.tsx
  6. 11
      libs/remix-ui/git/src/state/gitpayload.ts
  7. 25
      libs/remix-ui/git/src/state/gitreducer.tsx
  8. 18
      libs/remix-ui/git/src/types/index.ts

@ -348,9 +348,7 @@ class AppComponent {
solidityScript, solidityScript,
templates, templates,
openaigpt, openaigpt,
copilotSuggestion, git
git,
solcoder
]) ])
//---- fs plugin //---- fs plugin

@ -269,7 +269,6 @@ class DGitProvider extends Plugin {
const status = await git.log({ const status = await git.log({
...await this.addIsomorphicGitConfigFS(), ...await this.addIsomorphicGitConfigFS(),
...cmd, ...cmd,
depth: 10
}) })
return status return status
} }
@ -999,16 +998,18 @@ class DGitProvider extends Plugin {
} }
} }
async remotecommits(input: { owner: string, repo: string, token: string, branch: string, length: number }): Promise<pagedCommits[]> { async remotecommits(input: { owner: string, repo: string, token: string, branch: string, length: number,page: number }): Promise<pagedCommits[]> {
const octokit = new Octokit({ const octokit = new Octokit({
auth: input.token auth: input.token
}) })
input.length = input.length || 5
input.page = input.page || 1
const response = await octokit.request('GET /repos/{owner}/{repo}/commits', { const response = await octokit.request('GET /repos/{owner}/{repo}/commits', {
owner: input.owner, owner: input.owner,
repo: input.repo, repo: input.repo,
sha: input.branch, sha: input.branch,
per_page: 10 per_page: input.length,
page: input.page
}) })
const pages: pagedCommits[] = [] const pages: pagedCommits[] = []
const readCommitResults: ReadCommitResult[] = [] const readCommitResults: ReadCommitResult[] = []
@ -1050,8 +1051,8 @@ class DGitProvider extends Plugin {
console.log("Has next page:", hasNextPage); console.log("Has next page:", hasNextPage);
pages.push({ pages.push({
page: 1, page: input.page,
perPage: 10, perPage: input.length,
total: response.data.length, total: response.data.length,
hasNextPage: hasNextPage, hasNextPage: hasNextPage,
commits: readCommitResults commits: readCommitResults

@ -19,14 +19,33 @@ export const BranchDetails = (props: BrancheDetailsProps) => {
const actions = React.useContext(gitActionsContext) const actions = React.useContext(gitActionsContext)
const context = React.useContext(gitPluginContext) const context = React.useContext(gitPluginContext)
const [activePanel, setActivePanel] = useState<string>(""); const [activePanel, setActivePanel] = useState<string>("");
const [hasNextPage, setHasNextPage] = useState<boolean>(false)
const [lastPageNumber, setLastPageNumber] = useState<number>(0)
useEffect(() => { useEffect(() => {
if (activePanel === "0") { if (activePanel === "0") {
console.log('GET BRANCH COMMITS', branch) console.log('GET BRANCH COMMITS', branch)
actions.getBranchCommits(branch) if(lastPageNumber === 0)
actions.getBranchCommits(branch, 1)
} }
}, [activePanel]) }, [activePanel])
useEffect(() => {
let hasNextPage = false
let lastPageNumber = 0
console.log('BRANCH COMMITS', context.remoteBranchCommits)
context.remoteBranchCommits && Object.entries(context.remoteBranchCommits).map(([key, value]) => {
if(key == branch.name){
value.map((page, index) => {
hasNextPage = page.hasNextPage
lastPageNumber = page.page
})
}
})
setHasNextPage(hasNextPage)
setLastPageNumber(lastPageNumber)
}, [context.remoteBranchCommits])
const checkout = (branch: branch) => { const checkout = (branch: branch) => {
actions.checkout({ actions.checkout({
ref: branch.name, ref: branch.name,
@ -34,6 +53,11 @@ export const BranchDetails = (props: BrancheDetailsProps) => {
}); });
} }
const loadNextPage = () => {
console.log('LOAD NEXT PAGE', lastPageNumber+1)
actions.getBranchCommits(branch, lastPageNumber+1)
}
const checkoutCommit = async (oid: string) => { const checkoutCommit = async (oid: string) => {
try { try {
//await ModalRef.current?.show(); //await ModalRef.current?.show();
@ -49,7 +73,7 @@ export const BranchDetails = (props: BrancheDetailsProps) => {
<Accordion.Collapse className="pl-2 border-left ml-1" eventKey="0"> <Accordion.Collapse className="pl-2 border-left ml-1" eventKey="0">
<> <>
<div className="ml-1"> <div className="ml-1">
{context.branchCommits && Object.entries(context.branchCommits).map(([key, value]) => { {context.remoteBranchCommits && Object.entries(context.remoteBranchCommits).map(([key, value]) => {
if(key == branch.name){ if(key == branch.name){
return value.map((page, index) => { return value.map((page, index) => {
return page.commits.map((commit, index) => { return page.commits.map((commit, index) => {
@ -61,7 +85,7 @@ export const BranchDetails = (props: BrancheDetailsProps) => {
</div> </div>
<div>Load more</div> {hasNextPage && <a href="#" className="cursor-pointer mb-1 ml-2" onClick={loadNextPage}>Load more</a>}
</> </>
</Accordion.Collapse> </Accordion.Collapse>
</Accordion>) </Accordion>)

@ -1,7 +1,7 @@
import { ViewPlugin } from "@remixproject/engine-web"; import { ViewPlugin } from "@remixproject/engine-web";
import { ReadBlobResult, ReadCommitResult } from "isomorphic-git"; import { ReadBlobResult, ReadCommitResult } from "isomorphic-git";
import React from "react"; import React from "react";
import { fileStatus, fileStatusMerge, setBranchCommits, setBranches, setCanCommit, setCommitChanges, setCommits, setCurrentBranch, setGitHubUser, setLoading, setRateLimit, setRemoteBranches, setRemotes, setRepos, setUpstream } from "../state/gitpayload"; import { fileStatus, fileStatusMerge, setRemoteBranchCommits, setBranches, setCanCommit, setCommitChanges, setCommits, setCurrentBranch, setGitHubUser, setLoading, setRateLimit, setRemoteBranches, setRemotes, setRepos, setUpstream } from "../state/gitpayload";
import { GitHubUser, RateLimit, branch, commitChange, gitActionDispatch, statusMatrixType, gitState } from '../types'; import { GitHubUser, RateLimit, branch, commitChange, gitActionDispatch, statusMatrixType, gitState } from '../types';
import { removeSlash } from "../utils"; import { removeSlash } from "../utils";
import { disableCallBacks, enableCallBacks } from "./listeners"; import { disableCallBacks, enableCallBacks } from "./listeners";
@ -696,11 +696,25 @@ export const getCommitChanges = async (oid1: string, oid2: string) => {
return result return result
} }
export const fetchBranch = async (branch: branch) => { async function getRepoDetails(url: string) {
// Extract the owner and repo name from the URL
const pathParts = new URL(url).pathname.split('/').filter(part => part);
if (pathParts.length < 2) {
throw new Error("URL must be in the format 'https://github.com/[owner]/[repository]'");
}
const owner = pathParts[0];
const repo = pathParts[1];
return { owner, repo };
}
export const fetchBranch = async (branch: branch, page: number) => {
const token = await tokenWarning(); const token = await tokenWarning();
const rc = await plugin.call('dGitProvider' as any, 'remotecommits', { token, owner:'bunsenstraat', repo:'empty', branch:'main', length }); console.log('fetch', branch)
const { owner, repo } = await getRepoDetails(branch.remote.url);
const rc = await plugin.call('dGitProvider' as any, 'remotecommits', { token, owner: owner, repo: repo, branch: branch.name, length, page });
console.log(rc, 'remote commits from octokit') console.log(rc, 'remote commits from octokit')
dispatch(setBranchCommits({ branch, commits: rc })) dispatch(setRemoteBranchCommits({ branch, commits: rc }))
return return
const r = await plugin.call('dGitProvider', 'fetch', { const r = await plugin.call('dGitProvider', 'fetch', {
ref: branch.name, ref: branch.name,
@ -748,10 +762,10 @@ export const fetchBranch = async (branch: branch) => {
console.log(mergeCommits) console.log(mergeCommits)
//console.log(r, commits) //console.log(r, commits)
dispatch(setBranchCommits({ branch, commits: mergeCommits })) dispatch(setRemoteBranchCommits({ branch, commits: mergeCommits }))
} }
export const getBranchCommits = async (branch: branch) => { export const getBranchCommits = async (branch: branch, page: number) => {
try { try {
console.log(branch) console.log(branch)
if (!branch.remote) { if (!branch.remote) {
@ -759,12 +773,12 @@ export const getBranchCommits = async (branch: branch) => {
ref: branch.name, ref: branch.name,
}) })
console.log(commits) console.log(commits)
dispatch(setBranchCommits({ branch, commits })) //dispatch(setRemoteBranchCommits({ branch, commits }))
} else { } else {
await fetchBranch(branch) await fetchBranch(branch, page)
} }
} catch (e) { } catch (e) {
console.log(e) console.log(e)
await fetchBranch(branch) await fetchBranch(branch, page)
} }
} }

@ -17,7 +17,7 @@ export interface gitActions {
createBranch(branch: string): Promise<void> createBranch(branch: string): Promise<void>
remoteBranches(owner: string, repo: string): Promise<any> remoteBranches(owner: string, repo: string): Promise<any>
getCommitChanges(oid1: string, oid2: string): Promise<commitChange[]> getCommitChanges(oid1: string, oid2: string): Promise<commitChange[]>
getBranchCommits(branch: branch): Promise<void> getBranchCommits(branch: branch, page: number): Promise<void>
getGitHubUser(): Promise<any> getGitHubUser(): Promise<any>
diff(commitChange: commitChange): Promise<void> diff(commitChange: commitChange): Promise<void>
resolveRef(ref: string): Promise<string> resolveRef(ref: string): Promise<string>

@ -122,9 +122,16 @@ export const setCommitChanges = (commitChanges: commitChange[]) => {
} }
} }
export const setBranchCommits =({branch, commits}) => { export const setRemoteBranchCommits =({branch, commits}) => {
return { return {
type: 'SET_BRANCH_COMMITS', type: 'SET_REMOTE_BRANCH_COMMITS',
payload: { branch, commits }
}
}
export const setLocalBranchCommits = ({branch, commits}) => {
return {
type: 'SET_LOCAL_BRANCH_COMMITS',
payload: { branch, commits } payload: { branch, commits }
} }
} }

@ -1,6 +1,6 @@
import { ReadCommitResult } from "isomorphic-git" import { ReadCommitResult } from "isomorphic-git"
import { allChangedButNotStagedFiles, getFilesByStatus, getFilesWithNotModifiedStatus } from "../lib/fileHelpers" import { allChangedButNotStagedFiles, getFilesByStatus, getFilesWithNotModifiedStatus } from "../lib/fileHelpers"
import { branch, commitChange, defaultGitState, fileStatusResult, gitState, setBranchCommitsAction } from "../types" import { branch, commitChange, defaultGitState, fileStatusResult, gitState, setRemoteBranchCommitsAction, setLocalBranchCommitsAction } from "../types"
interface Action { interface Action {
type: string type: string
@ -118,13 +118,30 @@ export const gitReducer = (state: gitState = defaultGitState, action: Action): g
commitChanges: [...state.commitChanges] commitChanges: [...state.commitChanges]
} }
case 'SET_BRANCH_COMMITS': case 'SET_REMOTE_BRANCH_COMMITS':
state.branchCommits[(action as setBranchCommitsAction).payload.branch.name] = (action as setBranchCommitsAction).payload.commits if(state.remoteBranchCommits[(action as setRemoteBranchCommitsAction).payload.branch.name]){
state.remoteBranchCommits[(action as setRemoteBranchCommitsAction).payload.branch.name].push(...(action as setRemoteBranchCommitsAction).payload.commits)
}else{
state.remoteBranchCommits[(action as setRemoteBranchCommitsAction).payload.branch.name] = (action as setRemoteBranchCommitsAction).payload.commits
}
return {
...state,
remoteBranchCommits: {...state.remoteBranchCommits}
}
case 'SET_LOCAL_BRANCH_COMMITS':
if(state.localBranchCommits[(action as setLocalBranchCommitsAction).payload.branch.name]){
state.localBranchCommits[(action as setLocalBranchCommitsAction).payload.branch.name].push(...(action as setLocalBranchCommitsAction).payload.commits)
}else{
state.localBranchCommits[(action as setLocalBranchCommitsAction).payload.branch.name] = (action as setLocalBranchCommitsAction).payload.commits
}
return { return {
...state, ...state,
branchCommits: {...state.branchCommits} localBranchCommits: {...state.localBranchCommits}
} }
case 'SET_GITHUB_ACCESS_TOKEN':
case 'SET_GITHUB_USER': case 'SET_GITHUB_USER':
return { return {
...state, ...state,

@ -25,7 +25,8 @@ export type gitState = {
repositories: repository[] repositories: repository[]
remoteBranches: remoteBranch[] remoteBranches: remoteBranch[]
commitChanges: commitChange[] commitChanges: commitChange[]
branchCommits: Record<string, pagedCommits[]> remoteBranchCommits: Record<string, pagedCommits[]>
localBranchCommits: Record<string, pagedCommits[]>
syncStatus: syncStatus, syncStatus: syncStatus,
localCommitCount: number localCommitCount: number
remoteCommitCount: number remoteCommitCount: number
@ -121,7 +122,8 @@ export const defaultGitState: gitState = {
repositories: [], repositories: [],
remoteBranches: [], remoteBranches: [],
commitChanges: [], commitChanges: [],
branchCommits: {}, remoteBranchCommits: {},
localBranchCommits: {},
syncStatus: syncStatus.none, syncStatus: syncStatus.none,
localCommitCount: 0, localCommitCount: 0,
remoteCommitCount: 0, remoteCommitCount: 0,
@ -214,7 +216,15 @@ export interface setUpstreamAction {
payload: string payload: string
} }
export interface setBranchCommitsAction { export interface setRemoteBranchCommitsAction {
type: string,
payload: {
branch: branch,
commits: pagedCommits[]
}
}
export interface setLocalBranchCommitsAction {
type: string, type: string,
payload: { payload: {
branch: branch, branch: branch,
@ -227,4 +237,4 @@ export interface setTokenAction {
payload: string payload: string
} }
export type gitActionDispatch = setTokenAction | setUpstreamAction | setBranchCommitsAction | setRemotesAction | setCurrentBranchAction | fileStatusAction | setLoadingAction | setCanUseAppAction | setRepoNameAction | setCommitsAction | setBranchesAction | setReposAction | setRemoteBranchesAction export type gitActionDispatch = setTokenAction | setUpstreamAction | setRemoteBranchCommitsAction | setLocalBranchCommitsAction | setRemotesAction | setCurrentBranchAction | fileStatusAction | setLoadingAction | setCanUseAppAction | setRepoNameAction | setCommitsAction | setBranchesAction | setReposAction | setRemoteBranchesAction
Loading…
Cancel
Save