Skip to content

Commit 1f571ca

Browse files
author
Philippe Charrière
authored
Merge pull request #1 from bots-squad/wip-first
πŸš€ go ❗️
2 parents b9209f5 + 5de2f0a commit 1f571ca

File tree

13 files changed

+287
-3
lines changed

13 files changed

+287
-3
lines changed

β€Ž.gitignore

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
1+
# launcher
2+
# go.js
3+
4+
# shared repositories
5+
repos/*
6+
!repos/init-bare-repo.sh
7+
!repos/README.md
8+
9+
# sandbox
10+
sandbox/babs/*
11+
sandbox/buster/*
12+
!sandbox/babs/*.sh
13+
!sandbox/babs/README.md
14+
!sandbox/buster/*.sh
15+
!sandbox/buster/README.md
16+
17+
# things
18+
articles/
19+
.idea/
120
node_modules/
221
npm-debug.log
322
.DS_Store
4-
sandbox/
5-
RSRC.md
23+
rsrc/
24+
TODO.md

β€ŽREADME.md

Lines changed: 120 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,121 @@
11
# gitoonet
2-
stay tuned :panda_face:
2+
3+
stay tuned :panda_face: - v1.0.0 - :construction:
4+
5+
## What? Why?
6+
7+
- this is an educative tool
8+
- I need a simple tool to train myself with git, feature flow, ... and simulate "working with team".
9+
- I use https://github.com/substack/git-http-backend wit ExpressJS
10+
11+
## How to
12+
13+
### 1- launch the "git" server
14+
15+
> update settings in `go.js` (or manually set variables and run `git-server.js`)
16+
> variables:
17+
> - GIT_HTTP_PORT
18+
> - GIT_SHARED_REPOSITORIES_LOCATION: the sub directory to store git shared repositories (default is `repos`)
19+
20+
```
21+
./go.js
22+
```
23+
24+
### 2- create a shared repository
25+
26+
> planned with the next version: you'll be able to do this from the browser
27+
28+
- go to the `GIT_SHARED_REPOSITORIES_LOCATION` sub directory (eg: `cd repos`)
29+
- type (eg) `./init-bare-repo acme yo`, it will create a shared repository `yo.git` for the owner/organization `acme`:
30+
```
31+
β”œβ”€β”€ acme
32+
β”‚Β Β  └── yo.git
33+
β”‚Β Β  β”œβ”€β”€ HEAD
34+
β”‚Β Β  β”œβ”€β”€ branches
35+
β”‚Β Β  β”œβ”€β”€ config
36+
β”‚Β Β  β”œβ”€β”€ description
37+
β”‚Β Β  β”œβ”€β”€ hooks
38+
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ applypatch-msg.sample
39+
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ commit-msg.sample
40+
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ post-update.sample
41+
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ pre-applypatch.sample
42+
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ pre-commit.sample
43+
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ pre-push.sample
44+
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ pre-rebase.sample
45+
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ pre-receive.sample
46+
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ prepare-commit-msg.sample
47+
β”‚Β Β  β”‚Β Β  └── update.sample
48+
β”‚Β Β  β”œβ”€β”€ info
49+
β”‚Β Β  β”‚Β Β  └── exclude
50+
β”‚Β Β  β”œβ”€β”€ objects
51+
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ info
52+
β”‚Β Β  β”‚Β Β  └── pack
53+
β”‚Β Β  └── refs
54+
β”‚Β Β  β”œβ”€β”€ heads
55+
β”‚Β Β  └── tags
56+
```
57+
58+
### 3- use it
59+
60+
#### You are @babs
61+
62+
- initialize a repository named `yo` (of the `acme` organization) and set the `config` file of the repository as if you are **babs**:
63+
```
64+
mkdir yo
65+
cd yo
66+
git init
67+
echo "[user]" >> .git/config
68+
echo " name = babs" >> .git/config
69+
echo " email = [email protected]" >> .git/config
70+
```
71+
- create a file with content:
72+
```
73+
cd yo
74+
echo "# Yo project" > README.md
75+
git add .
76+
git commit -m "add README.md"
77+
git push http://localhost:5555/gitsrv/acme/yo.git master
78+
```
79+
- go to `/repos/acme/yo.git`
80+
- type `git log`, and you'll get something like that:
81+
```
82+
commit 61de85e64436c8ca5efa3ad6f7b28c27a5e4d4de
83+
Author: babs <[email protected]>
84+
Date: Thu Dec 15 07:25:13 2016 +0100
85+
```
86+
87+
#### You are @buster
88+
89+
Now, you can play as an other user: **buster**:
90+
91+
- clone the repository named `yo` (of the `acme` organization) and set the `config` file of the repository as if you are **buster**:
92+
```
93+
git clone http://localhost:5555/gitsrv/acme/yo.git
94+
cd yo
95+
echo "[user]" >> .git/config
96+
echo " name = buster" >> .git/config
97+
echo " email = [email protected]" >> .git/config
98+
```
99+
- add a new file and push to the server:
100+
```
101+
cd yo
102+
echo "some documentation" > DOC.md
103+
git add .
104+
git commit -m "add DOC.md"
105+
git push http://localhost:5555/gitsrv/acme/yo.git master
106+
```
107+
- go to `/repos/acme/yo.git`
108+
- type `git log`, and you'll get something like that:
109+
```
110+
commit 9f9b0b0fc0ef37ed9b8b89f9367aadf23c6ba525
111+
Author: buster <[email protected]>
112+
Date: Thu Dec 15 07:31:28 2016 +0100
113+
114+
add DOC.md
115+
116+
commit 61de85e64436c8ca5efa3ad6f7b28c27a5e4d4de
117+
Author: babs <[email protected]>
118+
Date: Thu Dec 15 07:25:13 2016 +0100
119+
```
120+
121+
> more to come... :construction:

β€Žgit-server.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env node
2+
const express = require('express');
3+
const bodyParser = require('body-parser');
4+
5+
const spawn = require('child_process').spawn;
6+
const path = require('path');
7+
const backend = require('git-http-backend');
8+
9+
const zlib = require('zlib');
10+
11+
12+
/*
13+
Express application
14+
*/
15+
let app = express();
16+
app.use(bodyParser.json());
17+
app.use(bodyParser.urlencoded({extended: false}));
18+
app.use(express.static('./public'));
19+
20+
21+
app.all('/gitsrv/*', (req, res) => {
22+
23+
console.log("---------------------------------------")
24+
console.log("url", req.url);
25+
console.log("params", req.params);
26+
console.log("query", req.query);
27+
console.log("method", req.method);
28+
console.log("headers", req.headers);
29+
console.log("---------------------------------------")
30+
31+
let splittedURL = req.url.split('/');
32+
let user = splittedURL[2];
33+
let repo = splittedURL[3];
34+
35+
var dir = path.join(__dirname, `${process.env.GIT_SHARED_REPOSITORIES_LOCATION}/${user}`, repo);
36+
37+
//TODO: check if directory exists
38+
39+
req = req.headers['content-encoding'] == 'gzip' ? req.pipe(zlib.createGunzip()) : req;
40+
41+
req.pipe(backend(req.url, function (err, service) {
42+
if (err) return res.end(err + '\n');
43+
44+
res.setHeader('content-type', service.type);
45+
46+
console.log("+++++++++++++++++++++++++++++++++++++++")
47+
48+
console.log(`service.action: ${service.action}`);
49+
console.log(`repo: ${repo}`);
50+
console.log('service.fields: ', service.fields);
51+
console.log(`service.cmd: ${service.cmd}`);
52+
console.log(`service.args: ${service.args}`);
53+
console.log("+++++++++++++++++++++++++++++++++++++++")
54+
55+
var ps = spawn(service.cmd, service.args.concat(dir));
56+
ps.stdout.pipe(service.createStream()).pipe(ps.stdin);
57+
58+
})).pipe(res);
59+
});
60+
61+
app.listen(process.env.GIT_HTTP_PORT)
62+
63+
console.log(`πŸš€ Git Server is started - listening on ${process.env.GIT_HTTP_PORT}`);
64+
console.log(__dirname);

β€Žgo.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env node
2+
"use strict";
3+
require('shelljs/global');
4+
5+
process.env["GIT_HTTP_PORT"] = 5555;
6+
process.env["GIT_SHARED_REPOSITORIES_LOCATION"] = "repos"
7+
8+
exec(`./git-server.js`)

β€Žpackage.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
"dependencies": {
2020
"body-parser": "^1.15.2",
2121
"express": "^4.14.0",
22+
"express-jwt": "^5.1.0",
2223
"git-http-backend": "^1.0.2",
24+
"jsonwebtoken": "^7.1.9",
25+
"jwt-simple": "^0.5.1",
2326
"node-fetch": "^1.6.3",
27+
"nohm": "^0.9.8",
2428
"shelljs": "^0.7.5",
2529
"uuid": "^3.0.0"
2630
}

β€Žpublic/index.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>GitOOnet</title>
6+
</head>
7+
<body>
8+
9+
<script src="js/riot+compiler.min.js"></script>
10+
</body>
11+
</html>

β€Žrepos/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# "bare" repositories
2+
3+
> `bare` repositories are here
4+
5+
## Structure
6+
7+
```
8+
└── user_name
9+
β”œβ”€β”€ repo-1
10+
└── repo-2
11+
```
12+
13+
## Initialize a shared repository
14+
15+
```
16+
./init-bare-repo.sh user_name repository_name
17+
```

β€Žrepos/init-bare-repo.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
# initialize a shared repository for a user
3+
# ./init-bare-repo.sh user_name repository_name
4+
mkdir -p $1
5+
cd $1
6+
git init $2.git --bare -q

β€Žsandbox/babs/init.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
# ./init.sh repository
3+
mkdir $1
4+
cd $1
5+
git init
6+
7+
echo "[user]" >> .git/config
8+
echo " name = babs" >> .git/config
9+
echo " email = [email protected]" >> .git/config

β€Žsandbox/babs/push.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
# ./push.sh owner_name repository
3+
cd $2
4+
echo "# Yo project" > README.md
5+
git add .
6+
git commit -m "add README.md"
7+
git push http://localhost:5555/gitsrv/$1/$2.git master

β€Žsandbox/babs/sync.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
# ./sync.sh owner_name repository
3+
cd $2
4+
git pull http://localhost:5555/gitsrv/$1/$2.git

β€Žsandbox/buster/clone.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
# ./clone.sh owner_name repository
3+
4+
git clone http://localhost:5555/gitsrv/$1/$2.git
5+
cd $2
6+
echo "[user]" >> .git/config
7+
echo " name = buster" >> .git/config
8+
echo " email = [email protected]" >> .git/config

β€Žsandbox/buster/push.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
# ./push.sh owner_name repository
3+
4+
cd $2
5+
echo "some documentation" > DOC.md
6+
git add .
7+
git commit -m "add DOC.md"
8+
git push http://localhost:5555/gitsrv/$1/$2.git master

0 commit comments

Comments
Β (0)