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,
templates,
openaigpt,
copilotSuggestion,
git,
solcoder
git
])
//---- fs plugin

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

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

@ -1,7 +1,7 @@
import { ViewPlugin } from "@remixproject/engine-web";
import { ReadBlobResult, ReadCommitResult } from "isomorphic-git";
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 { removeSlash } from "../utils";
import { disableCallBacks, enableCallBacks } from "./listeners";
@ -696,11 +696,25 @@ export const getCommitChanges = async (oid1: string, oid2: string) => {
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 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')
dispatch(setBranchCommits({ branch, commits: rc }))
dispatch(setRemoteBranchCommits({ branch, commits: rc }))
return
const r = await plugin.call('dGitProvider', 'fetch', {
ref: branch.name,
@ -748,10 +762,10 @@ export const fetchBranch = async (branch: branch) => {
console.log(mergeCommits)
//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 {
console.log(branch)
if (!branch.remote) {
@ -759,12 +773,12 @@ export const getBranchCommits = async (branch: branch) => {
ref: branch.name,
})
console.log(commits)
dispatch(setBranchCommits({ branch, commits }))
//dispatch(setRemoteBranchCommits({ branch, commits }))
} else {
await fetchBranch(branch)
await fetchBranch(branch, page)
}
} catch (e) {
console.log(e)
await fetchBranch(branch)
await fetchBranch(branch, page)
}
}

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

@ -1,6 +1,6 @@
import { ReadCommitResult } from "isomorphic-git"
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 {
type: string
@ -118,13 +118,30 @@ export const gitReducer = (state: gitState = defaultGitState, action: Action): g
commitChanges: [...state.commitChanges]
}
case 'SET_BRANCH_COMMITS':
state.branchCommits[(action as setBranchCommitsAction).payload.branch.name] = (action as setBranchCommitsAction).payload.commits
case 'SET_REMOTE_BRANCH_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 {
...state,
branchCommits: {...state.branchCommits}
localBranchCommits: {...state.localBranchCommits}
}
case 'SET_GITHUB_ACCESS_TOKEN':
case 'SET_GITHUB_USER':
return {
...state,

@ -25,7 +25,8 @@ export type gitState = {
repositories: repository[]
remoteBranches: remoteBranch[]
commitChanges: commitChange[]
branchCommits: Record<string, pagedCommits[]>
remoteBranchCommits: Record<string, pagedCommits[]>
localBranchCommits: Record<string, pagedCommits[]>
syncStatus: syncStatus,
localCommitCount: number
remoteCommitCount: number
@ -121,7 +122,8 @@ export const defaultGitState: gitState = {
repositories: [],
remoteBranches: [],
commitChanges: [],
branchCommits: {},
remoteBranchCommits: {},
localBranchCommits: {},
syncStatus: syncStatus.none,
localCommitCount: 0,
remoteCommitCount: 0,
@ -214,7 +216,15 @@ export interface setUpstreamAction {
payload: string
}
export interface setBranchCommitsAction {
export interface setRemoteBranchCommitsAction {
type: string,
payload: {
branch: branch,
commits: pagedCommits[]
}
}
export interface setLocalBranchCommitsAction {
type: string,
payload: {
branch: branch,
@ -227,4 +237,4 @@ export interface setTokenAction {
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