-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
COMMIT0-57 api for generating project #68
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a2e9234
COMMIT0-57 api for generating project
0a31ebb
COMMIT0-57-refactor
589ece0
COMMIT0-57 address some comments use commit0 template
5f181fa
COMMIT0-57 remove bin
b1392ba
COMMIT0-57 correct file path
262df53
COMMIT0-57 missed
f4f7d96
COMMIT0-57 readme
47df1bf
COMMIT0-57 attempt to add api cmd
0e2f336
COMMIT0-57 fix api
e2c783b
COMMIT0-57 ui
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/commitdev/commit0/internal/api" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(commit0api) | ||
} | ||
|
||
var commit0api = &cobra.Command{ | ||
Use: "ui", | ||
Short: "Run Commit0 Api", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
api.Commit0Api() | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Commit0 Api | ||
|
||
## Usage | ||
- To run: | ||
`commit0 api` | ||
- Endpoint: | ||
- POST `localhost:8080/{version}/generate` | ||
- Post request body json example: | ||
``` { | ||
"projectName":"funApp", | ||
"frontendFramework":"react", | ||
"organization":"commit org", | ||
"description":"this app will do amazing things", | ||
"maintainers":[ | ||
{ | ||
"name":"Lill", | ||
"email":"ll@gmail.com" | ||
}, | ||
{ | ||
"name":"Pi", | ||
"email":"pi@live.ca" | ||
} | ||
], | ||
"services":[ | ||
{ | ||
"name":"user", | ||
"description":"user service", | ||
"language":"go", | ||
"gitRepo":"github.com/user" | ||
}, | ||
{ | ||
"name":"account", | ||
"description":"bank account service", | ||
"language":"go", | ||
"gitRepo":"github.com/account" | ||
} | ||
] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package api | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"path" | ||
"sync" | ||
|
||
"github.com/commitdev/commit0/internal/config" | ||
"github.com/commitdev/commit0/internal/generate" | ||
"github.com/commitdev/commit0/internal/templator" | ||
"github.com/commitdev/commit0/internal/util" | ||
"github.com/gobuffalo/packr/v2" | ||
) | ||
|
||
func createProject(projectConfig util.ProjectConfiguration) string { | ||
templates := packr.New("templates", "../../templates") | ||
t := templator.NewTemplator(templates) | ||
outDir := "./" | ||
rootDir := path.Join(outDir, projectConfig.ProjectName) | ||
log.Printf("Creating project %s.", projectConfig.ProjectName) | ||
err := os.MkdirAll(rootDir, os.ModePerm) | ||
|
||
if os.IsExist(err) { | ||
log.Fatalf("Directory %v already exists! Error: %v", projectConfig.ProjectName, err) | ||
} else if err != nil { | ||
log.Fatalf("Error creating root: %v ", err) | ||
} | ||
var wg sync.WaitGroup | ||
|
||
util.TemplateFileIfDoesNotExist(rootDir, util.CommitYml, t.Commit0, &wg, projectConfig) | ||
|
||
util.TemplateFileIfDoesNotExist(rootDir, ".gitignore", t.GitIgnore, &wg, projectConfig.ProjectName) | ||
|
||
wg.Wait() | ||
|
||
GenerateArtifacts(projectConfig) | ||
|
||
return rootDir | ||
} | ||
|
||
func GenerateArtifacts(projectConfig util.ProjectConfiguration) { | ||
|
||
templates := packr.New("templates", "../templates") | ||
t := templator.NewTemplator(templates) | ||
|
||
generatedYml := path.Join(projectConfig.ProjectName, util.CommitYml) | ||
|
||
cfg := config.LoadConfig(generatedYml) | ||
cfg.Print() | ||
|
||
generate.GenerateArtifactsHelper(t, cfg, projectConfig.ProjectName) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/gorilla/mux" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/commitdev/commit0/internal/util" | ||
) | ||
|
||
func generateProject(w http.ResponseWriter, req *http.Request) { | ||
w.Header().Set("Content-Type", "application/json") | ||
switch req.Method { | ||
case "POST": | ||
decoder := json.NewDecoder(req.Body) | ||
var projectConfig util.ProjectConfiguration | ||
err := decoder.Decode(&projectConfig) | ||
if err != nil { | ||
panic(err) | ||
} | ||
log.Println(projectConfig.ProjectName) | ||
createProject(projectConfig) | ||
w.WriteHeader(http.StatusCreated) | ||
w.Write([]byte(`{"message": "Post successful"}`)) | ||
|
||
default: | ||
w.WriteHeader(http.StatusNotFound) | ||
w.Write([]byte(`{"message": "Not found"}`)) | ||
} | ||
|
||
} | ||
|
||
func Commit0Api() { | ||
var router = mux.NewRouter() | ||
var api = router.PathPrefix("/v1/generate").Subrouter() | ||
api.NotFoundHandler = http.HandlerFunc(generateProject) | ||
|
||
log.Fatal(http.ListenAndServe(":8080", router)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to add validation for post request