Skip to content

Commit 657a98c

Browse files
committed
b
1 parent d1f9081 commit 657a98c

File tree

13 files changed

+615
-2
lines changed

13 files changed

+615
-2
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Function; Git Branch List
2+
FUNCTION ==> git-branch-list
3+
4+
Lists branches in Git repository
5+
6+
___
7+
FUNCTION_INVOCATION[/misc/workflows/workflows/git/git-branch-list.hl]:
8+
{
9+
"path": "[STRING_VALUE]"
10+
}
11+
___
12+
13+
## Arguments
14+
15+
* `path` is the mandatory folder of where your repository is.
16+
17+
Notice, you can only save files in the "/etc/" and "/modules/" folders, so the `path` argument must point inside of "/etc/" or "/modules/".
18+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Function; Git Fetch
2+
FUNCTION ==> git-fetch
3+
4+
Fetches all changes from a remote.
5+
6+
___
7+
FUNCTION_INVOCATION[/misc/workflows/workflows/git/git-fetch.hl]:
8+
{
9+
"path": "[STRING_VALUE]",
10+
"remote": "[STRING_VALUE]",
11+
"refspec": "[STRING_VALUE]"
12+
}
13+
___
14+
15+
## Arguments
16+
17+
* `path` is the mandatory folder of where your repository is.
18+
* `remote` is optional named remote. Defaults to 'origin'.
19+
* `refspec` is optional refspec to fetch.
20+
21+
Notice, you can only save files in the "/etc/" and "/modules/" folders, so the `path` argument must point inside of "/etc/" or "/modules/".
22+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Function; Git Pull
2+
FUNCTION ==> git-pull
3+
4+
Pulls all changes from a remote.
5+
6+
___
7+
FUNCTION_INVOCATION[/misc/workflows/workflows/git/git-pull.hl]:
8+
{
9+
"path": "[STRING_VALUE]",
10+
"remote": "[STRING_VALUE]",
11+
"branch": "[STRING_VALUE]"
12+
}
13+
___
14+
15+
## Arguments
16+
17+
* `path` is the mandatory folder of where your repository is.
18+
* `remote` is optional named remote. Defaults to 'origin'.
19+
* `branch` is the optional branch to pull. Defaults to 'main'.
20+
21+
Notice, you can only save files in the "/etc/" and "/modules/" folders, so the `path` argument must point inside of "/etc/" or "/modules/".
22+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Function; Git Status
2+
FUNCTION ==> git-status
3+
4+
Shows repo status.
5+
6+
___
7+
FUNCTION_INVOCATION[/misc/workflows/workflows/git/git-status.hl]:
8+
{
9+
"path": "[STRING_VALUE]"
10+
}
11+
___
12+
13+
## Arguments
14+
15+
* `path` is the mandatory folder of where your repository is.
16+
17+
Notice, you can only save files in the "/etc/" and "/modules/" folders, so the `path` argument must point inside of "/etc/" or "/modules/".
18+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
/*
3+
* Lists all Git branches in repo.
4+
*
5+
* Arguments:
6+
*
7+
* - [path] is mandatory folder of where repo is locally on dics.
8+
*/
9+
.arguments
10+
11+
// Mandatory folder to where Git repo is locally on dics.
12+
path:string
13+
14+
// Ensuring user is root.
15+
auth.ticket.verify:root
16+
17+
// Sanity checking invocation.
18+
validators.mandatory:x:@.arguments/*/path
19+
20+
// Sanity checking invocation.
21+
if
22+
and
23+
not
24+
strings.starts-with:x:@.arguments/*/path
25+
.:/modules/
26+
not
27+
strings.starts-with:x:@.arguments/*/path
28+
.:/etc/
29+
.lambda
30+
throw:"Git repos must be in folders inside of either '/etc/' or '/modules/'"
31+
32+
// Invoking slot.
33+
git.branch.list:x:@.arguments/*/path
34+
35+
// Returning result
36+
return-nodes:x:@git.branch.list/*
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
/*
3+
* Fetch an existing Git repository.
4+
*
5+
* Arguments:
6+
*
7+
* - [path] is mandatory folder of where repo is locally on dics.
8+
* - [remote] is optional argument for a named remote such as 'origin'.
9+
* - [refspec] is optional argument for the refspec.
10+
*/
11+
.arguments
12+
13+
// Mandatory folder to where Git repo is locally on dics.
14+
path:string
15+
16+
// Optional argument being a named remote. Defaults to 'origin'.
17+
remote:string
18+
19+
// Optional argument being the refspec.
20+
refspec:string
21+
22+
// Ensuring user is root.
23+
auth.ticket.verify:root
24+
25+
// Sanity checking invocation.
26+
validators.mandatory:x:@.arguments/*/path
27+
validators.default:x:@.arguments
28+
remote:origin
29+
30+
// Sanity checking invocation.
31+
if
32+
and
33+
not
34+
strings.starts-with:x:@.arguments/*/path
35+
.:/modules/
36+
not
37+
strings.starts-with:x:@.arguments/*/path
38+
.:/etc/
39+
.lambda
40+
throw:"Git repos must be in folders inside of either '/etc/' or '/modules/'"
41+
42+
// Parametrising slot
43+
add:x:./*/git.fetch
44+
get-nodes:x:@.arguments/*/remote
45+
get-nodes:x:@.arguments/*/refspec
46+
47+
// Invoking slot.
48+
git.fetch:x:@.arguments/*/path
49+
50+
// Returning success
51+
yield
52+
result:success
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
/*
3+
* Pulls an existing Git repository.
4+
*
5+
* Arguments:
6+
*
7+
* - [path] is mandatory folder of where repo is locally on dics.
8+
* - [remote] is optional argument for a named remote such as 'origin' and defaults to 'origin'.
9+
* - [branch] is optional argument for what branch to pull and defaults to 'main'.
10+
*/
11+
.arguments
12+
13+
// Mandatory folder to where Git repo is locally on dics.
14+
path:string
15+
16+
// Optional argument being a named remote. Defaults to 'origin'.
17+
remote:string
18+
19+
// Optional argument being the refspec.
20+
branch:string
21+
22+
// Ensuring user is root.
23+
auth.ticket.verify:root
24+
25+
// Sanity checking invocation.
26+
validators.mandatory:x:@.arguments/*/path
27+
validators.default:x:@.arguments
28+
remote:origin
29+
branch:main
30+
31+
// Sanity checking invocation.
32+
if
33+
and
34+
not
35+
strings.starts-with:x:@.arguments/*/path
36+
.:/modules/
37+
not
38+
strings.starts-with:x:@.arguments/*/path
39+
.:/etc/
40+
.lambda
41+
throw:"Git repos must be in folders inside of either '/etc/' or '/modules/'"
42+
43+
// Parametrising slot
44+
add:x:./*/git.pull
45+
get-nodes:x:@.arguments/*/remote
46+
get-nodes:x:@.arguments/*/branch
47+
48+
// Invoking slot.
49+
git.pull:x:@.arguments/*/path
50+
51+
// Returning success
52+
yield
53+
result:success
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
/*
3+
* Shows Git repository status
4+
*
5+
* Arguments:
6+
*
7+
* - [path] is mandatory folder of where repo is locally on dics.
8+
*/
9+
.arguments
10+
11+
// Mandatory folder to where Git repo is locally on dics.
12+
path:string
13+
14+
// Ensuring user is root.
15+
auth.ticket.verify:root
16+
17+
// Sanity checking invocation.
18+
validators.mandatory:x:@.arguments/*/path
19+
20+
// Sanity checking invocation.
21+
if
22+
and
23+
not
24+
strings.starts-with:x:@.arguments/*/path
25+
.:/modules/
26+
not
27+
strings.starts-with:x:@.arguments/*/path
28+
.:/etc/
29+
.lambda
30+
throw:"Git repos must be in folders inside of either '/etc/' or '/modules/'"
31+
32+
// Invoking slot.
33+
git.status:x:@.arguments/*/path
34+
35+
// Returning success
36+
yield
37+
result:x:@git.status
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) Thomas Hansen, 2021 - 2023 thomas@ainiro.io.
3+
*/
4+
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using magic.node;
8+
using magic.node.contracts;
9+
using magic.node.extensions;
10+
using magic.signals.contracts;
11+
using Microsoft.Extensions.Configuration;
12+
13+
namespace magic.lambda.git
14+
{
15+
/// <summary>
16+
/// [git.branch.list] slot to list branches.
17+
/// </summary>
18+
[Slot(Name = "git.branch.list")]
19+
public class GitBranchList : ISlotAsync
20+
{
21+
readonly IRootResolver _rootResolver;
22+
readonly IConfiguration _configuration;
23+
24+
public GitBranchList(IRootResolver rootResolver, IConfiguration configuration)
25+
{
26+
_rootResolver = rootResolver;
27+
_configuration = configuration;
28+
}
29+
30+
public async Task SignalAsync(ISignaler signaler, Node input)
31+
{
32+
var args = GetArgs(input);
33+
34+
var gitArgs = GitSlotHelpers.Args("branch");
35+
if (args.Remote)
36+
gitArgs.Add("-r");
37+
if (args.All)
38+
gitArgs.Add("-a");
39+
40+
var repoPath = GitSlotHelpers.ResolveRepoPath(_rootResolver, args.Path);
41+
var result = await GitSlotHelpers.RunGitAsync(
42+
repoPath,
43+
gitArgs,
44+
GitSlotHelpers.GetGitHubAuthArgs(_configuration));
45+
46+
input.Clear();
47+
input.Value = null;
48+
if (!string.IsNullOrWhiteSpace(result))
49+
{
50+
foreach (var line in result.Split('\n'))
51+
{
52+
var name = line.Trim().TrimStart('*').Trim();
53+
if (string.IsNullOrWhiteSpace(name))
54+
continue;
55+
input.Add(new Node(".", name));
56+
}
57+
}
58+
}
59+
60+
#region [ -- Private helper methods -- ]
61+
62+
(string Path, bool Remote, bool All) GetArgs(Node input)
63+
{
64+
var path = GitSlotHelpers.GetRequiredPrimaryValue(input);
65+
var remote = input.Children.FirstOrDefault(x => x.Name == "remote")?.GetEx<bool>() ?? false;
66+
var all = input.Children.FirstOrDefault(x => x.Name == "all")?.GetEx<bool>() ?? false;
67+
68+
input.Clear();
69+
input.Value = null;
70+
71+
return (path, remote, all);
72+
}
73+
74+
#endregion
75+
}
76+
}

0 commit comments

Comments
 (0)