aboutsummaryrefslogtreecommitdiffstats
path: root/misc
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-06 14:08:43 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-06 14:11:10 +0200
commit2adca224f055fe74ac714f9a102deff7380d783f (patch)
tree6f96c9f6f6a96bdeb1fa0913c338f44249b6cc62 /misc
parent62b57b008baa90b2e322cfb9c1cf997330429642 (diff)
downloadgit-bug-2adca224f055fe74ac714f9a102deff7380d783f.tar.gz
random bugs: cleanup + generate random OperationPack as well
Diffstat (limited to 'misc')
-rw-r--r--misc/random_bugs/create_random_bugs.go60
-rw-r--r--misc/random_bugs/main.go2
2 files changed, 55 insertions, 7 deletions
diff --git a/misc/random_bugs/create_random_bugs.go b/misc/random_bugs/create_random_bugs.go
index 46ca7964..87845b3c 100644
--- a/misc/random_bugs/create_random_bugs.go
+++ b/misc/random_bugs/create_random_bugs.go
@@ -29,11 +29,26 @@ func DefaultOptions() Options {
}
}
-func GenerateRandomBugs(repo repository.Repo, opts Options) {
- GenerateRandomBugsWithSeed(repo, opts, time.Now().UnixNano())
+func CommitRandomBugs(repo repository.Repo, opts Options) {
+ CommitRandomBugsWithSeed(repo, opts, time.Now().UnixNano())
}
-func GenerateRandomBugsWithSeed(repo repository.Repo, opts Options, seed int64) {
+func CommitRandomBugsWithSeed(repo repository.Repo, opts Options, seed int64) {
+ bugs := GenerateRandomBugsWithSeed(opts, seed)
+
+ for _, b := range bugs {
+ err := b.Commit(repo)
+ if err != nil {
+ panic(err)
+ }
+ }
+}
+
+func GenerateRandomBugs(opts Options) []*bug.Bug {
+ return GenerateRandomBugsWithSeed(opts, time.Now().UnixNano())
+}
+
+func GenerateRandomBugsWithSeed(opts Options, seed int64) []*bug.Bug {
rand.Seed(seed)
fake.Seed(seed)
@@ -46,6 +61,8 @@ func GenerateRandomBugsWithSeed(repo repository.Repo, opts Options, seed int64)
operations.Close,
}
+ result := make([]*bug.Bug, opts.BugNumber)
+
for i := 0; i < opts.BugNumber; i++ {
addedLabels = []string{}
@@ -61,11 +78,42 @@ func GenerateRandomBugsWithSeed(repo repository.Repo, opts Options, seed int64)
opsGenerators[index](b, randomPerson(opts.PersonNumber))
}
- err = b.Commit(repo)
- if err != nil {
- panic(err)
+ result[i] = b
+ }
+
+ return result
+}
+
+func GenerateRandomOperationPacks(packNumber int, opNumber int) []*bug.OperationPack {
+ return GenerateRandomOperationPacksWithSeed(packNumber, opNumber, time.Now().UnixNano())
+}
+
+func GenerateRandomOperationPacksWithSeed(packNumber int, opNumber int, seed int64) []*bug.OperationPack {
+ // Note: this is a bit crude, only generate a Create + Comments
+
+ rand.Seed(seed)
+ fake.Seed(seed)
+
+ result := make([]*bug.OperationPack, packNumber)
+
+ for i := 0; i < packNumber; i++ {
+ opp := &bug.OperationPack{}
+
+ var op bug.Operation
+
+ op = operations.NewCreateOp(randomPerson(5), fake.Sentence(), paragraphs(), nil)
+
+ opp.Append(op)
+
+ for j := 0; j < opNumber-1; j++ {
+ op = operations.NewAddCommentOp(randomPerson(5), paragraphs(), nil)
+ opp.Append(op)
}
+
+ result[i] = opp
}
+
+ return result
}
func person() bug.Person {
diff --git a/misc/random_bugs/main.go b/misc/random_bugs/main.go
index 7211548e..31b12e45 100644
--- a/misc/random_bugs/main.go
+++ b/misc/random_bugs/main.go
@@ -24,5 +24,5 @@ func main() {
panic(err)
}
- rb.GenerateRandomBugs(repo, rb.DefaultOptions())
+ rb.CommitRandomBugs(repo, rb.DefaultOptions())
}