How to use addCommitsToBug method of main Package

Best Syzkaller code snippet using main.addCommitsToBug

api.go

Source:api.go Github

copy

Full Screen

...240 if err := json.Unmarshal(payload, req); err != nil {241 return nil, fmt.Errorf("failed to unmarshal request: %v", err)242 }243 // This adds fixing commits to bugs.244 err := addCommitsToBugs(c, ns, "", nil, req.Commits)245 if err != nil {246 return nil, err247 }248 // Now add commit info to commits.249 for _, com := range req.Commits {250 if com.Hash == "" {251 continue252 }253 if err := addCommitInfo(c, ns, com); err != nil {254 return nil, err255 }256 }257 return nil, nil258}259func addCommitInfo(c context.Context, ns string, com dashapi.Commit) error {260 var bugs []*Bug261 keys, err := db.NewQuery("Bug").262 Filter("Namespace=", ns).263 Filter("Commits=", com.Title).264 GetAll(c, &bugs)265 if err != nil {266 return fmt.Errorf("failed to query bugs: %v", err)267 }268 for i, bug := range bugs {269 if err := addCommitInfoToBug(c, bug, keys[i], com); err != nil {270 return err271 }272 }273 return nil274}275func addCommitInfoToBug(c context.Context, bug *Bug, bugKey *db.Key, com dashapi.Commit) error {276 if needUpdate, err := addCommitInfoToBugImpl(c, bug, com); err != nil {277 return err278 } else if !needUpdate {279 return nil280 }281 tx := func(c context.Context) error {282 bug := new(Bug)283 if err := db.Get(c, bugKey, bug); err != nil {284 return fmt.Errorf("failed to get bug %v: %v", bugKey.StringID(), err)285 }286 if needUpdate, err := addCommitInfoToBugImpl(c, bug, com); err != nil {287 return err288 } else if !needUpdate {289 return nil290 }291 if _, err := db.Put(c, bugKey, bug); err != nil {292 return fmt.Errorf("failed to put bug: %v", err)293 }294 return nil295 }296 return db.RunInTransaction(c, tx, nil)297}298func addCommitInfoToBugImpl(c context.Context, bug *Bug, com dashapi.Commit) (bool, error) {299 ci := -1300 for i, title := range bug.Commits {301 if title == com.Title {302 ci = i303 break304 }305 }306 if ci < 0 {307 return false, nil308 }309 for len(bug.CommitInfo) < len(bug.Commits) {310 bug.CommitInfo = append(bug.CommitInfo, Commit{})311 }312 hash0 := bug.CommitInfo[ci].Hash313 date0 := bug.CommitInfo[ci].Date314 author0 := bug.CommitInfo[ci].Author315 needCommitInfo0 := bug.NeedCommitInfo316 bug.CommitInfo[ci].Hash = com.Hash317 bug.CommitInfo[ci].Date = com.Date318 bug.CommitInfo[ci].Author = com.Author319 bug.NeedCommitInfo = false320 for i := range bug.CommitInfo {321 if bug.CommitInfo[i].Hash == "" {322 bug.NeedCommitInfo = true323 break324 }325 }326 changed := hash0 != bug.CommitInfo[ci].Hash ||327 date0 != bug.CommitInfo[ci].Date ||328 author0 != bug.CommitInfo[ci].Author ||329 needCommitInfo0 != bug.NeedCommitInfo330 return changed, nil331}332func apiJobPoll(c context.Context, r *http.Request, payload []byte) (interface{}, error) {333 req := new(dashapi.JobPollReq)334 if err := json.Unmarshal(payload, req); err != nil {335 return nil, fmt.Errorf("failed to unmarshal request: %v", err)336 }337 if len(req.Managers) == 0 {338 return nil, fmt.Errorf("no managers")339 }340 return pollPendingJobs(c, req.Managers)341}342func apiJobDone(c context.Context, r *http.Request, payload []byte) (interface{}, error) {343 req := new(dashapi.JobDoneReq)344 if err := json.Unmarshal(payload, req); err != nil {345 return nil, fmt.Errorf("failed to unmarshal request: %v", err)346 }347 err := doneJob(c, req)348 return nil, err349}350func apiUploadBuild(c context.Context, ns string, r *http.Request, payload []byte) (interface{}, error) {351 req := new(dashapi.Build)352 if err := json.Unmarshal(payload, req); err != nil {353 return nil, fmt.Errorf("failed to unmarshal request: %v", err)354 }355 now := timeNow(c)356 _, isNewBuild, err := uploadBuild(c, now, ns, req, BuildNormal)357 if err != nil {358 return nil, err359 }360 if isNewBuild {361 err := updateManager(c, ns, req.Manager, func(mgr *Manager, stats *ManagerStats) error {362 prevKernel, prevSyzkaller := "", ""363 if mgr.CurrentBuild != "" {364 prevBuild, err := loadBuild(c, ns, mgr.CurrentBuild)365 if err != nil {366 return err367 }368 prevKernel = prevBuild.KernelCommit369 prevSyzkaller = prevBuild.SyzkallerCommit370 }371 log.Infof(c, "new build on %v: kernel %v->%v syzkaller %v->%v",372 req.Manager, prevKernel, req.KernelCommit, prevSyzkaller, req.SyzkallerCommit)373 mgr.CurrentBuild = req.ID374 if req.KernelCommit != prevKernel {375 mgr.FailedBuildBug = ""376 }377 if req.SyzkallerCommit != prevSyzkaller {378 mgr.FailedSyzBuildBug = ""379 }380 return nil381 })382 if err != nil {383 return nil, err384 }385 }386 if len(req.Commits) != 0 || len(req.FixCommits) != 0 {387 for i := range req.FixCommits {388 // Reset hashes just to make sure,389 // the build does not necessary come from the master repo, so we must not remember hashes.390 req.FixCommits[i].Hash = ""391 }392 if err := addCommitsToBugs(c, ns, req.Manager, req.Commits, req.FixCommits); err != nil {393 // We've already uploaded the build successfully and manager can use it.394 // Moreover, addCommitsToBugs scans all bugs and can take long time.395 // So just log the error.396 log.Errorf(c, "failed to add commits to bugs: %v", err)397 }398 }399 return nil, nil400}401func uploadBuild(c context.Context, now time.Time, ns string, req *dashapi.Build, typ BuildType) (402 *Build, bool, error) {403 if build, err := loadBuild(c, ns, req.ID); err == nil {404 return build, false, nil405 }406 checkStrLen := func(str, name string, maxLen int) error {407 if str == "" {408 return fmt.Errorf("%v is empty", name)409 }410 if len(str) > maxLen {411 return fmt.Errorf("%v is too long (%v)", name, len(str))412 }413 return nil414 }415 if err := checkStrLen(req.Manager, "Build.Manager", MaxStringLen); err != nil {416 return nil, false, err417 }418 if err := checkStrLen(req.ID, "Build.ID", MaxStringLen); err != nil {419 return nil, false, err420 }421 if err := checkStrLen(req.KernelRepo, "Build.KernelRepo", MaxStringLen); err != nil {422 return nil, false, err423 }424 if len(req.KernelBranch) > MaxStringLen {425 return nil, false, fmt.Errorf("Build.KernelBranch is too long (%v)", len(req.KernelBranch))426 }427 if err := checkStrLen(req.SyzkallerCommit, "Build.SyzkallerCommit", MaxStringLen); err != nil {428 return nil, false, err429 }430 if len(req.CompilerID) > MaxStringLen {431 return nil, false, fmt.Errorf("Build.CompilerID is too long (%v)", len(req.CompilerID))432 }433 if len(req.KernelCommit) > MaxStringLen {434 return nil, false, fmt.Errorf("Build.KernelCommit is too long (%v)", len(req.KernelCommit))435 }436 configID, err := putText(c, ns, textKernelConfig, req.KernelConfig, true)437 if err != nil {438 return nil, false, err439 }440 build := &Build{441 Namespace: ns,442 Manager: req.Manager,443 ID: req.ID,444 Type: typ,445 Time: now,446 OS: req.OS,447 Arch: req.Arch,448 VMArch: req.VMArch,449 SyzkallerCommit: req.SyzkallerCommit,450 SyzkallerCommitDate: req.SyzkallerCommitDate,451 CompilerID: req.CompilerID,452 KernelRepo: req.KernelRepo,453 KernelBranch: req.KernelBranch,454 KernelCommit: req.KernelCommit,455 KernelCommitTitle: req.KernelCommitTitle,456 KernelCommitDate: req.KernelCommitDate,457 KernelConfig: configID,458 }459 if _, err := db.Put(c, buildKey(c, ns, req.ID), build); err != nil {460 return nil, false, err461 }462 return build, true, nil463}464func addCommitsToBugs(c context.Context, ns, manager string, titles []string, fixCommits []dashapi.Commit) error {465 presentCommits := make(map[string]bool)466 bugFixedBy := make(map[string][]string)467 for _, com := range titles {468 presentCommits[com] = true469 }470 for _, com := range fixCommits {471 presentCommits[com.Title] = true472 for _, bugID := range com.BugIDs {473 bugFixedBy[bugID] = append(bugFixedBy[bugID], com.Title)474 }475 }476 managers, err := managerList(c, ns)477 if err != nil {478 return err479 }480 // Fetching all bugs in a namespace can be slow, and there is no way to filter only Open/Dup statuses.481 // So we run a separate query for each status, this both avoids fetching unnecessary data482 // and splits a long query into two (two smaller queries have lower chances of trigerring483 // timeouts than one huge).484 for _, status := range []int{BugStatusOpen, BugStatusDup} {485 err := addCommitsToBugsInStatus(c, status, ns, manager, managers, presentCommits, bugFixedBy)486 if err != nil {487 return err488 }489 }490 return nil491}492func addCommitsToBugsInStatus(c context.Context, status int, ns, manager string, managers []string,493 presentCommits map[string]bool, bugFixedBy map[string][]string) error {494 bugs, _, err := loadAllBugs(c, func(query *db.Query) *db.Query {495 return query.Filter("Namespace=", ns).496 Filter("Status=", status)497 })498 if err != nil {499 return err500 }501 for _, bug := range bugs {502 var fixCommits []string503 for i := range bug.Reporting {504 fixCommits = append(fixCommits, bugFixedBy[bug.Reporting[i].ID]...)505 }506 sort.Strings(fixCommits)507 if err := addCommitsToBug(c, bug, manager, managers, fixCommits, presentCommits); err != nil {508 return err509 }510 if bug.Status == BugStatusDup {511 canon, err := canonicalBug(c, bug)512 if err != nil {513 return err514 }515 if canon.Status == BugStatusOpen && len(bug.Commits) == 0 {516 if err := addCommitsToBug(c, canon, manager, managers,517 fixCommits, presentCommits); err != nil {518 return err519 }520 }521 }522 }523 return nil524}525func addCommitsToBug(c context.Context, bug *Bug, manager string, managers []string,526 fixCommits []string, presentCommits map[string]bool) error {527 if !bugNeedsCommitUpdate(c, bug, manager, fixCommits, presentCommits, true) {528 return nil529 }530 now := timeNow(c)531 bugKey := bug.key(c)532 tx := func(c context.Context) error {533 bug := new(Bug)534 if err := db.Get(c, bugKey, bug); err != nil {535 return fmt.Errorf("failed to get bug %v: %v", bugKey.StringID(), err)536 }537 if !bugNeedsCommitUpdate(c, bug, manager, fixCommits, presentCommits, false) {538 return nil539 }...

Full Screen

Full Screen

addCommitsToBug

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 addCommitsToBug("1")4}5func addCommitsToBug(bugID string) {6 branch, err := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD").Output()7 if err != nil {8 log.Fatal(err)9 }10 commit, err := exec.Command("git", "rev-parse", "HEAD").Output()11 if err != nil {12 log.Fatal(err)13 }14 msg, err := exec.Command("git", "log", "-1", "--pretty=%B").Output()15 if err != nil {16 log.Fatal(err)17 }18 author, err := exec.Command("git", "log", "-1", "--pretty=%ae").Output()19 if err != nil {20 log.Fatal(err)21 }22 date, err := exec.Command("git", "log", "-1", "--pretty=%ad").Output()23 if err != nil {24 log.Fatal(err)25 }26 hash, err := exec.Command("git", "log", "-1", "--pretty=%h").Output()27 if err != nil {28 log.Fatal(err)29 }30 remote, err := exec.Command("git", "config", "--get", "remote.origin.url").Output()31 if err != nil {32 log.Fatal(err)33 }34 remote, err := exec.Command("git", "config", "--get", "remote.origin.url").Output()35 if err != nil {36 log.Fatal(err)37 }38 remote, err := exec.Command("git", "config", "--get", "remote.origin.url").Output()39 if err != nil {40 log.Fatal(err)41 }42 remote, err := exec.Command("git", "config", "--get", "remote.origin.url").Output()

Full Screen

Full Screen

addCommitsToBug

Using AI Code Generation

copy

Full Screen

1import (2type Commit struct {3}4type Bug struct {5}6func main() {7 r, err := git.PlainOpen("C:/Users/Abhishek/Desktop/Go/src/github.com/kr/pretty")8 if err != nil {9 log.Fatal(err)10 }11 ref, err := r.Head()12 if err != nil {13 log.Fatal(err)14 }15 commit, err := r.CommitObject(ref.Hash())16 if err != nil {17 log.Fatal(err)18 }19 cIter, err := r.Log(&git.LogOptions{From: ref.Hash()})20 if err != nil {21 log.Fatal(err)22 }23 err = cIter.ForEach(func(c *object.Commit) error {24 commitHash = c.Hash.String()25 commitDate = c.Author.When.String()26 commit = Commit{Hash: commitHash, Author: commitAuthor, Date: commitDate, Message: commitMessage}

Full Screen

Full Screen

addCommitsToBug

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 file, err := os.Open("commits.txt")4 if err != nil {5 fmt.Println(err)6 }7 defer file.Close()8 scanner := bufio.NewScanner(file)9 for scanner.Scan() {10 line := scanner.Text()11 split := strings.Split(line, ",")12 addCommitsToBug(bugID, commitID)13 }14}15import (16func main() {17 file, err := os.Open("commits.txt")18 if err != nil {19 fmt.Println(err)20 }21 defer file.Close()22 scanner := bufio.NewScanner(file)23 for scanner.Scan() {24 line := scanner.Text()25 split := strings.Split(line, ",")26 addCommitsToBug(bugID, commitID)27 }28}29import (30func main() {31 file, err := os.Open("commits.txt")32 if err != nil {33 fmt.Println(err)34 }35 defer file.Close()36 scanner := bufio.NewScanner(file)37 for scanner.Scan() {38 line := scanner.Text()39 split := strings.Split(line, ",")

Full Screen

Full Screen

addCommitsToBug

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 m := new(Main)4 m.addCommitsToBug()5}6import (7func main() {8 m := new(Main)9 m.addCommitsToBug()10}11import (12func main() {13 m := new(Main)14 m.addCommitsToBug()15}16import (17func main() {18 m := new(Main)19 m.addCommitsToBug()20}21import (22func main() {23 m := new(Main)24 m.addCommitsToBug()25}26import (27func main() {28 m := new(Main)29 m.addCommitsToBug()30}31import (

Full Screen

Full Screen

addCommitsToBug

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 b, err := ioutil.ReadFile("commits.txt")4 if err != nil {5 fmt.Print(err)6 }7 text := string(b)8 lines := strings.Split(text, "9 for i, line := range lines {10 fmt.Println(i, line)11 }12 for i, line := range lines {13 fmt.Println(i, line)14 }15 for i, line := range lines {16 fmt.Println(i, line)17 }18 for i, line := range lines {19 fmt.Println(i, line)20 }21}22import (23func main() {24 b, err := ioutil.ReadFile("commits.txt")25 if err != nil {26 fmt.Print(err)27 }28 text := string(b)29 lines := strings.Split(text, "30 for i, line := range lines {31 fmt.Println(i, line)32 }33 for i, line := range lines {34 fmt.Println(i, line)35 }36 for i, line := range lines {37 fmt.Println(i, line)38 }39 for i, line := range lines {40 fmt.Println(i, line)41 }42}43import (44func main() {

Full Screen

Full Screen

addCommitsToBug

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 bug := getBug()4 addCommitsToBug(bug)5 fmt.Println(bug)6}7import (8type Bug struct {9}10func addCommitsToBug(bug *Bug) {11 bug.Commits = append(bug.Commits, "commit1", "commit2")12}13func getBug() *Bug {14 return &Bug{15 Commits: []string{},16 }17}18{1 bug1 description of bug1 [commit1 commit2]}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful