Skip to content

Commit

Permalink
Add Taskfile git addon
Browse files Browse the repository at this point in the history
  • Loading branch information
rick-nu committed Nov 6, 2024
1 parent 45e36a5 commit cf6074a
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 8 deletions.
20 changes: 14 additions & 6 deletions src/components/Form/Checkbox/checkbox.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
display: block;
padding: 0.3rem 0.5rem 0.3rem 2rem;
background-color: #f0f0f0;
border-radius: 0.2rem;
border-radius: 0.1rem;
cursor: pointer;
transition: background-color 500ms;
}
Expand All @@ -27,13 +27,13 @@
.checkbox span::before {
content: '';
background-color: #fff;
width: 1rem;
height: 1rem;
width: 20px;
height: 20px;
position: absolute;
top: 50%;
left: 0.5rem;
left: 5px;
transform: translateY(-50%);
border-radius: 0.2rem;
border-radius: 0.1rem;
transition: background-color 250ms;
}

Expand All @@ -42,6 +42,14 @@
outline: 0.2rem solid #a1e1aa;
}

.checkbox input:checked + span::before {
.checkbox input:checked + span::after {
content: '';
background-color: #2ac93f;
width: 14px;
height: 14px;
position: absolute;
top: 50%;
left: 8px;
transform: translateY(-50%);
border-radius: 0.1rem;
}
4 changes: 2 additions & 2 deletions src/components/Form/Radio/radio.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
top: 50%;
left: 0.4rem;
transform: translateY(-50%);
border-radius: 1rem;
border-radius: 50%;
}

.option input:focus + span,
Expand All @@ -60,5 +60,5 @@
top: 50%;
left: 0.6rem;
transform: translateY(-50%);
border-radius: 1rem;
border-radius: 50%;
}
3 changes: 3 additions & 0 deletions src/components/Generator/Generator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export type GeneratorSettings = {
font: Font;
runtime: 'local' | 'docker-compose';
developmentProxy: boolean;
checkoutGitRequest: 'none' | 'github' | 'gitlab';
linkGitHooks: boolean;
}

const Generator = (): ReactElement => {
Expand All @@ -24,6 +26,7 @@ const Generator = (): ReactElement => {
project: 'Taskfile',
font: 'Shadow',
runtime: 'local',
checkoutGitRequest: 'none',
},
});

Expand Down
3 changes: 3 additions & 0 deletions src/components/Generator/GeneredTaskfile/addons/addons.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { GeneratorSettings } from '@/components/Generator';
import { TaskfileAddons } from '@/components/Generator/GeneredTaskfile/taskfile';

import runtime from './runtime';
import git from './git';

/**
* Render addons for the Taskfile based on the generator settings
Expand All @@ -10,6 +12,7 @@ import runtime from './runtime';
*/
const renderAddons = (settings: GeneratorSettings, addons: TaskfileAddons): void => {
runtime(settings, addons);
git(settings, addons);
}

export default renderAddons;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function project:git-config {
title "Setting git configuration"
git config --local core.hooksPath dev/git-hooks
echo -e "Git hooks directory is set to ${YELLOW}./dev/git-hooks${RESET}."
}
25 changes: 25 additions & 0 deletions src/components/Generator/GeneredTaskfile/addons/git/git.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { GeneratorSettings } from '@/components/Generator';
import { TaskfileAddons } from '@/components/Generator/GeneredTaskfile/taskfile';
import loadTemplate from '@/helpers/loadTemplate';
import gitLinkHooks from './git-link-hooks.sh';
import githubFunction from './github-pr-function.sh';
import gitlabFunction from './gitlab-mr-function.sh';

const git = (settings: GeneratorSettings, addon: TaskfileAddons): void => {
if (settings.linkGitHooks) {
addon.projectFunctions.push(loadTemplate(gitLinkHooks));

addon.initCheckCommands.push('project:git-config');
}

switch (settings.checkoutGitRequest) {
case 'github':
addon.projectFunctions.push(loadTemplate(githubFunction));
break;
case 'gitlab':
addon.projectFunctions.push(loadTemplate(gitlabFunction));
break;
}
}

export default git;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function task:pr { ## Check out pull request <number> and update
project:checkout-pr $1
project:update
}

function project:checkout-pr {
title "Checking out pull request"
if [ -z "$1" ]; then
echo "You need to provide a pull request number to check out."
echo -e "${BLUE}Usage:${RESET} $0 pr ${YELLOW}<number>${RESET}"
exit 1
fi
echo "Checking out pull request $1..."
git fetch origin refs/pull/$1/head:refs/remotes/origin/pr/$1
git checkout origin/pr/$1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
function task:mr { ## Check out merge request <number> and update
project:checkout-mr $1
project:update
}

function project:checkout-mr {
title "Checking out merge request"
if [ -z "$1" ]; then
echo "You need to provide a merge request number to check out."
echo -e "${BLUE}Usage:${RESET} $0 mr ${YELLOW}<number>${RESET}"
exit 1
fi
echo "Checking out merge request $1..."
git fetch origin refs/merge-requests/$1/head:refs/remotes/origin/merge-requests/$1
git checkout origin/merge-requests/$1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default} from './git'
21 changes: 21 additions & 0 deletions src/components/Generator/Settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ const Settings = (): ReactElement => {
for local domains instead of ports
</Checkbox>
)}
<RadioInput
name="checkoutGitRequest"
title="Checkout merge/pull request number"
choices={[
{
label: 'None',
value: 'none',
},
{
label: 'GitHub PR',
value: 'github',
},
{
label: 'GitLab MR',
value: 'gitlab',
},
]}
/>
<Checkbox name="linkGitHooks">
Create git hooks symlink
</Checkbox>
</div>
)
}
Expand Down

0 comments on commit cf6074a

Please sign in to comment.