Revert "[M120 Migration]Fix for crash during chrome exit"
[platform/framework/web/chromium-efl.git] / tools / crbug / pinpoint.js
1 // Copyright 2022 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 'use strict';
6
7 const process = require('child_process');
8
9 class PinpointJob {
10   constructor(json) {
11     this.user_ = json.created_by;
12     this.timestamp_ = new Date(json.create_time.seconds * 1000);
13     this.crbug_ = json.job_spec.monorail_issue;
14     this.url_ = undefined;
15     this.project_ = undefined;
16
17     if (this.crbug_) {
18       const project = this.crbug_.project;
19       const num = this.crbug_.issue_id;
20       this.url_ =
21           `https://bugs.chromium.org/p/${project}/issues/detail?id=${num}`;
22       this.project_ = project;
23     }
24   }
25
26   get url() {
27     return this.url_;
28   }
29   get timestamp() {
30     return this.timestamp_;
31   }
32   get project() {
33     return this.project_;
34   }
35 };
36
37 class Pinpoint {
38   constructor() {}
39
40   listJobs(useremail) {
41     const args =
42         ['pinpoint', 'list-jobs', '--json', '--filter', `user=${useremail}`];
43     for (let tries = 0; tries < 3; ++tries) {
44       try {
45         const stdout = process.execSync(args.join(' ')).toString().trim();
46         const json = JSON.parse(stdout);
47         if (json) {
48           const jobs = json.map(j => new PinpointJob(j));
49           return jobs;
50         }
51       } catch (ex) {
52       }
53     }
54     return [];
55   }
56 };
57
58 async function test() {
59   const pinpoint = new Pinpoint();
60   const jobs = pinpoint.listJobs('sadrul@google.com');
61   console.log(jobs.filter(j => j.url)
62                   .map(j => `${j.timestamp.toLocaleDateString()},${j.url}`));
63 }
64
65 module.exports = {
66   Pinpoint,
67 };