Skip to content

Commit

Permalink
Resolve merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbrittain committed Sep 11, 2024
1 parent bc1af74 commit b6bdadd
Show file tree
Hide file tree
Showing 9 changed files with 307 additions and 0 deletions.
3 changes: 3 additions & 0 deletions electron-app/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export type SettingsAPI = {
GithubUnstageFiles: (query: Query) => Promise<Query>;
GithubCommit: (query: Query) => Promise<Query>;
GithubClone: (query: Query) => Promise<Query>;
<<<<<<< HEAD
GithubCommitAllChanges: (query: Query) => Promise<Query>;
=======
>>>>>>> 6d05798 (Resolve merge conflict)
};

declare global {
Expand Down
3 changes: 3 additions & 0 deletions electron-app/src/handles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ export async function settings_GithubClone(
) {
return await SafeProcessQuery(event, query, stderr_callback);
}
<<<<<<< HEAD

export async function settings_GithubCommitAllChanges(
event: Event,
Expand All @@ -494,3 +495,5 @@ export async function settings_GithubCommitAllChanges(
) {
return await SafeProcessQuery(event, query, stderr_callback);
}
=======
>>>>>>> 6d05798 (Resolve merge conflict)
3 changes: 3 additions & 0 deletions electron-app/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,12 @@ app.whenReady().then(() => {
ipcMain.handle('settings/github-clone', (event: Event, query: Query) =>
handles.settings_GithubClone(event, query, stderr_callback),
);
<<<<<<< HEAD
ipcMain.handle('settings/github-commit-all-changes', (event: Event, query: Query) =>
handles.settings_GithubCommitAllChanges(event, query, stderr_callback),
);
=======
>>>>>>> 6d05798 (Resolve merge conflict)
});

app.on('will-quit', () => {
Expand Down
3 changes: 3 additions & 0 deletions electron-app/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,11 @@ contextBridge.exposeInMainWorld('settingsAPI', {
GithubUnstageFiles: (query: Query) => ipcRenderer.invoke('settings/github-unstage-files', query),
GithubCommit: (query: Query) => ipcRenderer.invoke('settings/github-commit', query),
GithubClone: (query: Query) => ipcRenderer.invoke('settings/github-clone', query),
<<<<<<< HEAD
GithubCommitAllChanges: (query: Query) =>
ipcRenderer.invoke('settings/github-commit-all-changes', query),
=======
>>>>>>> 6d05798 (Resolve merge conflict)
});

declare global {
Expand Down
3 changes: 3 additions & 0 deletions electron-app/src/python/pyrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ def post(request):
),
"returncode": 0,
}
<<<<<<< HEAD
elif query == "settings/github-commit-all-changes":
author = data.get("author", None)
email = data.get("email", None)
Expand All @@ -402,6 +403,8 @@ def post(request):
"body": runner.github.Clone(data["url"], data["path"], create_folder),
"returncode": 0,
}
=======
>>>>>>> 6d05798 (Resolve merge conflict)

else:
raise NotImplementedError(f"Unknown query: {query}")
Expand Down
3 changes: 3 additions & 0 deletions nodemapper/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export type SettingsAPI = {
GithubUnstageFiles: (query: Query) => Promise<Query>;
GithubCommit: (query: Query) => Promise<Query>;
GithubClone: (query: Query) => Promise<Query>;
<<<<<<< HEAD
GithubCommitAllChanges: (query: Query) => Promise<Query>;
=======
>>>>>>> 6d05798 (Resolve merge conflict)
};

declare global {
Expand Down
272 changes: 272 additions & 0 deletions nodemapper/src/gui/Settings/RepoOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,289 @@ import { GithubMenu } from 'gui/Settings/RepoGhIndicator';

import CheckCircleIcon from '@mui/icons-material/CheckCircle';
import FolderOutlinedIcon from '@mui/icons-material/FolderOutlined';
import GitHubIcon from '@mui/icons-material/GitHub';
import HighlightOffIcon from '@mui/icons-material/HighlightOff';
import Alert from '@mui/material/Alert';
import Box from '@mui/material/Box';
import Button from '@mui/material/Button';
import CircularProgress from '@mui/material/CircularProgress';
import Divider from '@mui/material/Divider';
import IconButton from '@mui/material/IconButton';
import Menu from '@mui/material/Menu';
import MenuItem from '@mui/material/MenuItem';
import Tooltip from '@mui/material/Tooltip';
import Typography from '@mui/material/Typography';

<<<<<<< HEAD
import { DialogWait } from 'components/DialogWait';
import { DialogPrompt } from 'components/DialogPrompt';

const displayAPI = window.displayAPI;
const settingsAPI = window.settingsAPI;
=======
import { NestedMenuItem } from 'components/DropdownMenu';

const displayAPI = window.displayAPI;
const settingsAPI = window.settingsAPI;

interface GithubMenuProps {
repo: string;
branch: string;
}

const GithubMenu = ({ repo, branch }: GithubMenuProps) => {
const dispatch = useAppDispatch();
const [anchorMenu, setAnchorMenu] = React.useState<null | HTMLElement>(null);

// Github repo status
type ghStatusOpts =
| 'unknown'
| 'checking'
| 'not-a-repo'
| 'up-to-date'
| 'behind'
| 'ahead'
| 'diverged'
| 'error';
interface ghStatusProps {
status: ghStatusOpts;
message?: string;
}
const [ghStatus, setGhStatus] = React.useState({ status: 'unknown' } as ghStatusProps);

// Tracked files
type ghTrackedOpts = 'unknown' | 'checking' | 'some' | 'none' | 'error';
interface ghTrackedProps {
status: ghTrackedOpts;
message?: string;
modified_files?: string[];
added_files?: string[];
deleted_files?: string[];
}
const [ghTracked, setGhTracked] = React.useState({ status: 'unknown' } as ghTrackedProps);

// Untracked files
type ghUntrackedOpts = 'unknown' | 'checking' | 'some' | 'none' | 'error';
interface ghUntrackedProps {
status: ghUntrackedOpts;
untracked_files?: string[];
}
const [ghUntracked, setGhUntracked] = React.useState({ status: 'unknown' } as ghUntrackedProps);

type ghIndicatorOpts =
| 'unknown'
| 'checking'
| 'not-a-repo'
| 'up-to-date'
| 'modified'
| 'error';
const [ghIndicator, setGhIndicator] = React.useState('unknown' as ghIndicatorOpts);

// Get repo status
useEffect(() => {
if (ghStatus.status === 'unknown') {
GithubGetRepoStatus(repo, branch);
setGhIndicator('checking');
}
}, []);

const GithubGetRepoStatus = async (repo: string, branch: string) => {
// Check if the repo is in sync with the remote
const query = {
query: 'settings/github-get-repo-status',
data: {
repo: repo,
branch: branch,
},
};
const response_status = await settingsAPI.GithubGetRepoStatus(query);
const result_status = response_status['body'] as ghStatusProps;
setGhStatus(result_status);
if (result_status.status == 'error') {
dispatch(
builderLogEvent(`Error checking Github status for ${repo}: ${result_status.message}`),
);
setGhIndicator('error');
return;
}
if (result_status.status === 'not-a-repo') {
setGhIndicator('not-a-repo');
return;
}
// Check for tracked file changes
const query_tracked = {
query: 'settings/github-get-tracked-file-changes',
data: {
repo: repo,
},
};
const response_tracked = await settingsAPI.GithubGetRepoStatus(query_tracked);
const result_tracked = response_tracked['body'] as ghTrackedProps;
setGhTracked(result_tracked);

// Check for untracked files
const query_untracked = {
query: 'settings/github-get-untracked-files',
data: {
repo: repo,
},
};
const response_untracked = await settingsAPI.GithubGetRepoStatus(query_untracked);
const result_untracked = response_untracked['body'] as ghUntrackedProps;
setGhUntracked(result_untracked);

// Set the indicator
if (result_status.status === 'up-to-date') {
if (result_tracked.status === 'none' && result_untracked.status === 'none') {
setGhIndicator('up-to-date');
} else {
setGhIndicator('modified');
}
} else {
setGhIndicator('modified');
}
};

const onGhPull = async () => {
settingsAPI
.GithubPull({
query: 'settings/github-pull',
data: {
repo: repo,
branch: branch,
},
})
.then((response) => {
const result = response['body'] as { status: string; message: string };
if (result.status === 'success') {
// Force refresh of the repo status
} else {
dispatch(
builderLogEvent(`Error pulling changes from Github for ${repo}: ${result.message}`),
);
}
});
};

const onGhPush = async () => {
settingsAPI
.GithubPush({
query: 'settings/github-push',
data: {
repo: repo,
branch: branch,
},
})
.then((response) => {
const result = response['body'] as { status: string; message: string };
if (result.status === 'success') {
// Force refresh of the repo status
} else {
dispatch(
builderLogEvent(`Error pushing changes to Github for ${repo}: ${result.message}`),
);
}
});
};

return (
<>
<Box>
<IconButton
onClick={(e) => {
// Only permit the github menu to open if the repo has modified elements
setAnchorMenu(ghIndicator === 'modified' ? e.currentTarget : null);
}}
disableRipple // prevent field edit activating button on Enter
disableFocusRipple //
tabIndex={-1} //
>
{/* For 'unknown', 'checking' and 'not-a-repo' we don't show the github indicator */}
{ghIndicator === 'up-to-date' && (
<Tooltip title={ghStatus.message}>
<GitHubIcon style={{ color: '#424242' }} />
</Tooltip>
)}
{ghIndicator === 'checking' && (
<Tooltip title="Checking repository...">
<CircularProgress
size={20}
sx={{ color: '#424242' }} // dark grey
/>
</Tooltip>
)}
{ghIndicator === 'modified' && (
<Tooltip title={ghStatus.message}>
<GitHubIcon style={{ color: 'orange' }} />
</Tooltip>
)}
{ghStatus.status === 'error' && (
<Tooltip title={ghStatus.message}>
<GitHubIcon style={{ color: 'red' }} />
</Tooltip>
)}
</IconButton>
</Box>

{/* Drop-down menu (github) */}
<Menu
anchorEl={anchorMenu}
open={Boolean(anchorMenu)}
onClose={() => {
setAnchorMenu(null);
}}
>
<Box sx={{ minWidth: 150 }}>
{ghStatus.status === 'diverged' && (
<Alert severity="warning">
Conflicts with github detected - try pulling the latest changes
</Alert>
)}
{(ghStatus.status === 'behind' || ghStatus.status === 'diverged') && (
<Button variant="contained" fullWidth onClick={onGhPull}>
Pull latest changes from github
</Button>
)}
{ghStatus.status === 'ahead' && (
<Button variant="contained" fullWidth onClick={onGhPush}>
Push local updates to github
</Button>
)}
{(ghTracked.status === 'some' || ghUntracked.status === 'some') && <Divider />}
{ghTracked.status === 'some' && ghTracked.added_files.length > 0 && (
<NestedMenuItem label="Added files">
{ghTracked.added_files.map((file) => (
<MenuItem key={file}>{file}</MenuItem>
))}
</NestedMenuItem>
)}
{ghTracked.status === 'some' && ghTracked.modified_files.length > 0 && (
<NestedMenuItem label="Modified files">
{ghTracked.modified_files.map((file) => (
<MenuItem key={file}>{file}</MenuItem>
))}
</NestedMenuItem>
)}
{ghTracked.status === 'some' && ghTracked.deleted_files.length > 0 && (
<NestedMenuItem label="Deleted files">
{ghTracked.deleted_files.map((file) => (
<MenuItem key={file}>{file}</MenuItem>
))}
</NestedMenuItem>
)}
{ghUntracked.status === 'some' && ghUntracked.untracked_files.length > 0 && (
<NestedMenuItem label="Untracked files">
{ghUntracked.untracked_files.map((file) => (
<MenuItem key={file}>{file}</MenuItem>
))}
</NestedMenuItem>
)}
</Box>
</Menu>
</>
);
};
>>>>>>> 6d05798 (Resolve merge conflict)

const RepoOptions = () => {
const dispatch = useAppDispatch();
Expand Down
3 changes: 3 additions & 0 deletions runner/runner/github/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from .github import Clone # noqa: F401
from .github import Commit # noqa: F401
<<<<<<< HEAD
from .github import CommitAllChanges # noqa: F401
=======
>>>>>>> 6d05798 (Resolve merge conflict)
from .github import GetRepoStatus # noqa: F401
from .github import GetTrackedFileChanges # noqa: F401
from .github import GetUntrackedFiles # noqa: F401
Expand Down
Loading

0 comments on commit b6bdadd

Please sign in to comment.