Skip to content

Commit 662a4d8

Browse files
committed
add config tags
add git branch to config tags
1 parent 04ca726 commit 662a4d8

7 files changed

Lines changed: 23 additions & 7 deletions

File tree

api/handler_config.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package api
22

33
import (
44
"fmt"
5-
log "github.com/sirupsen/logrus"
65
"mime"
76
"mokapi/config/dynamic"
87
"net/http"
98
"path/filepath"
109
"strings"
1110
"time"
11+
12+
log "github.com/sirupsen/logrus"
1213
)
1314

1415
type config struct {
@@ -17,6 +18,7 @@ type config struct {
1718
Provider string `json:"provider"`
1819
Time time.Time `json:"time"`
1920
Refs []configRef `json:"refs,omitempty"`
21+
Tags []string `json:"tags,omitempty"`
2022
}
2123

2224
type configRef struct {
@@ -116,5 +118,6 @@ func toConfig(cfg *dynamic.Config) config {
116118
Time: cfg.Info.Time,
117119
Provider: cfg.Info.Provider,
118120
Refs: refs,
121+
Tags: cfg.Info.Tags,
119122
}
120123
}

config/dynamic/config_info.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package dynamic
33
import (
44
"crypto/md5"
55
"encoding/hex"
6-
"github.com/google/uuid"
7-
log "github.com/sirupsen/logrus"
86
"net/url"
97
"strings"
108
"time"
9+
10+
"github.com/google/uuid"
11+
log "github.com/sirupsen/logrus"
1112
)
1213

1314
type ConfigInfo struct {
@@ -16,6 +17,7 @@ type ConfigInfo struct {
1617
Checksum []byte
1718
Time time.Time
1819
inner *ConfigInfo
20+
Tags []string
1921
}
2022

2123
func (ci *ConfigInfo) Path() string {

config/dynamic/provider/git/git.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ func wrapConfig(c *dynamic.Config, r *repository) {
329329
// to query git log takes too long
330330
Time: time.Now(),
331331
}
332+
h, err := r.repo.Head()
333+
if err == nil {
334+
ref := h.Name()
335+
info.Tags = append(info.Tags, ref.Short())
336+
}
332337

333338
dynamic.Wrap(info, c)
334339
}

config/dynamic/provider/git/git_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func TestGit(t *testing.T) {
5555
require.Equal(t, "https://github.com/marle3003/mokapi-example.git?file=/"+name, c.Config.Info.Path())
5656
require.Contains(t, gitFiles, name)
5757
require.NotNil(t, c.Config.Info.Checksum)
58+
require.Equal(t, []string{"main"}, c.Config.Info.Tags)
5859
}
5960
}
6061
require.Equal(t, 4, count)

examples/mokapi/services_http.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ export const configs = {
112112
data: 'http://localhost:8090/api/services/http/Swagger%20Petstore',
113113
}
114114
],
115-
filename: 'petstore.json'
115+
filename: 'petstore.json',
116+
tags: ['Tag1', 'Tag2'],
116117
},
117118
'b6fea8ac-56c7-4e73-a9c0-4487640bdca8': {
118119
id: 'b6fea8ac-56c7-4e73-a9c0-4487640bdca8',

webui/src/components/dashboard/Config.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@ const provider = computed(() => {
6565
<section class="card" aria-label="Info">
6666
<div class="card-body">
6767
<div class="row">
68-
<div class="col-11 header mb-3">
68+
<div class="col header mb-3">
6969
<p id="url" class="label">URL</p>
7070
<p aria-labelledby="url">{{ config.url }}</p>
7171
</div>
72-
<div class="col-1 text-end">
73-
<span class="badge bg-secondary">Config</span>
72+
<div class="col text-end">
73+
<span v-if="config.tags" v-for="tag of config.tags" class="badge bg-primary ms-1">
74+
{{ tag }}
75+
</span>
76+
<span class="badge bg-secondary ms-1">Config</span>
7477
</div>
7578
</div>
7679
<div class="row">

webui/src/types/service.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ declare interface Config {
3939
provider: string
4040
time: string
4141
refs: ConfigRef[]
42+
tags?: string[]
4243
}
4344

4445
declare interface ConfigRef {

0 commit comments

Comments
 (0)