summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/catapult/third_party/polymer2/bower_components/chopsui/chops-bug-mixin.html
blob: 2ab9fb2bc0e4b75da17090f78c788e03be332a84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<script>
  'use strict';

  const bugIdRe = /[0-9]{3,}/;
  const bugRe = /([^0-9]*)?[0-9]{3,}([^0-9]*)?/;
  const bugProjectUrlRe = /(\/p\/[a-z0-9][-a-z0-9]*[a-z0-9]\/)/i;
  const bugProjectPairRe = /([a-z0-9][-a-z0-9]*[a-z0-9]:)/i;
  const bugProjectNameRe = /[a-z0-9][-a-z0-9]*[a-z0-9]/i;

  /**
   * A class mixin for use in parsing bug data.
   *
   * This class is based around parsing "bugString", a free form user bug input
   * that is in the format of a bug id, bug url, or a bug in the form of
   * 'projectName:bugId'.
   */
  // TODO(zhangtiff): Add support for Buganizer bugs here.
  var ChopsBugMixin = function(superClass) {
    return class extends superClass {
      constructor() {
        super();
      }

      _computeBugId(bugString) {
        return bugRe.test(bugString) ? bugIdRe.exec(bugString) : 'Unknown';
      }

      _computeBugProject(bugString) {
        let cleanBug = bugString.replace(/http(s?):/i, "");
        let projectSection = bugProjectUrlRe.exec(cleanBug) || bugProjectPairRe.exec(cleanBug);
        return projectSection ? bugProjectNameRe.exec(projectSection)[0] : 'chromium';
      }

      _computeInvalidBug(bugId) {
        return bugId == 'Unknown';
      }
    };
  }
</script>