-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c1668c6
commit d646ebd
Showing
11 changed files
with
159 additions
and
126 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
name: Go | ||
|
||
on: | ||
push: | ||
branches: [ "master" ] | ||
pull_request: | ||
branches: [ "master" ] | ||
|
||
jobs: | ||
|
||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.22' | ||
|
||
- name: Build | ||
run: go build -v ./... | ||
|
||
- name: Test | ||
run: go test -v ./... |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,5 @@ | ||
module github.com/LGBT-CN/signature-counter | ||
|
||
go 1.22.2 | ||
|
||
require github.com/KevinZonda/GoX v0.0.15 // indirect |
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,2 @@ | ||
github.com/KevinZonda/GoX v0.0.15 h1:u+G41/srg8c6bmI6Oqw9iBwYiSQk9FKp9fv/YBZadFk= | ||
github.com/KevinZonda/GoX v0.0.15/go.mod h1:WHV3YUyG+ou3wuUgwO4SRhMiKxLTVK5inajmtR1MUXo= |
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,70 @@ | ||
/* | ||
* Copyright (c) 2024. LGBT-CN & KevinZonda | ||
* This file is part of LGBT-CN Signature Counting. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/KevinZonda/GoX/pkg/iox" | ||
"github.com/KevinZonda/GoX/pkg/panicx" | ||
"github.com/KevinZonda/GoX/pkg/stringx" | ||
"os" | ||
"strings" | ||
) | ||
|
||
const SIGN_BEGIN = "<!-- BEGIN LGBT-CN SIGNATURE -->" | ||
const SIGN_END = "<!-- END LGBT-CN SIGNATURE -->" | ||
const COUNT_BEGIN = "<!-- BEGIN LGBT-CN COUNT -->" | ||
const COUNT_END = "<!-- END LGBT-CN COUNT -->" | ||
|
||
func main() { | ||
fileName := os.Args[1] | ||
txt, err := iox.ReadAllText(fileName) | ||
panicx.PanicIfNotNil(err, err) | ||
count, txt := GetSigCount(txt) | ||
txt = SetSigCount(txt, count) | ||
err = iox.WriteAllText(fileName, txt) | ||
|
||
} | ||
|
||
func Split(content string, beginToken string, endToken string) (string, string, string) { | ||
begins := strings.SplitN(content, beginToken, 2) | ||
token0 := strings.TrimSpace(begins[0]) | ||
|
||
content = begins[1] | ||
|
||
ends := strings.SplitN(content, endToken, 2) | ||
token1 := strings.TrimSpace(ends[0]) | ||
token2 := strings.TrimSpace(ends[1]) | ||
return token0, token1, token2 | ||
|
||
} | ||
|
||
func GetSigCount(txt string) (int, string) { | ||
header, content, footer := Split(txt, SIGN_BEGIN, SIGN_END) | ||
bodyLines := strings.Split(content, "\n") | ||
bodyLines = stringx.TrimAllAndClean(bodyLines) | ||
content = strings.Join(bodyLines, "\n") | ||
txt = strings.Join([]string{ | ||
header, | ||
SIGN_BEGIN, | ||
content, | ||
SIGN_END, | ||
footer, | ||
}, "\n") | ||
return len(bodyLines), txt | ||
} | ||
|
||
func SetSigCount(txt string, count int) string { | ||
header, _, footer := Split(txt, COUNT_BEGIN, COUNT_END) | ||
return strings.Join( | ||
[]string{ | ||
header, | ||
COUNT_BEGIN, | ||
fmt.Sprintf("已有 %d 人签署!", count), | ||
COUNT_END, | ||
footer, | ||
}, "\n") | ||
} |
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,47 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/KevinZonda/GoX/pkg/iox" | ||
"os" | ||
"testing" | ||
) | ||
|
||
const README = ` | ||
BEGIN | ||
<!-- BEGIN LGBT-CN SIGNATURE --> | ||
User1 | ||
User2 | ||
User5 | ||
<!-- END LGBT-CN SIGNATURE --> | ||
<!-- BEGIN LGBT-CN COUNT --> | ||
已有 -1 人签署! | ||
<!-- END LGBT-CN COUNT --> | ||
END | ||
` | ||
|
||
const EXPECTED = `BEGIN | ||
<!-- BEGIN LGBT-CN SIGNATURE --> | ||
User1 | ||
User2 | ||
User5 | ||
<!-- END LGBT-CN SIGNATURE --> | ||
<!-- BEGIN LGBT-CN COUNT --> | ||
已有 3 人签署! | ||
<!-- END LGBT-CN COUNT --> | ||
END` | ||
|
||
const TEST_FILE = "test.md" | ||
|
||
func TestMainFunc(t *testing.T) { | ||
//defer os.Remove(TEST_FILE) | ||
iox.WriteAllText(TEST_FILE, README) | ||
os.Args = []string{"main", TEST_FILE} | ||
main() | ||
txt, _ := iox.ReadAllText(TEST_FILE) | ||
if txt != EXPECTED { | ||
t.Errorf("Expected %s, got %s", EXPECTED, txt) | ||
return | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,10 @@ | ||
BEGIN | ||
<!-- BEGIN LGBT-CN SIGNATURE --> | ||
User1 | ||
User2 | ||
User5 | ||
<!-- END LGBT-CN SIGNATURE --> | ||
<!-- BEGIN LGBT-CN COUNT --> | ||
已有 3 人签署! | ||
<!-- END LGBT-CN COUNT --> | ||
END |