Skip to content

Commit

Permalink
Merge pull request #48 from moul/dev/moul/fix-parsing
Browse files Browse the repository at this point in the history
fix: fix parsing issue in 'depends on XXX' and 'blocked by XXX'
  • Loading branch information
moul authored Sep 14, 2018
2 parents d5b035c + 17fcaab commit eab47c5
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ func FromGitHubIssue(input *github.Issue) *Issue {
if input.Body != nil {
body = *input.Body
}
parts := strings.Split(*input.HTMLURL, "/")
issue := &Issue{
Provider: GitHubProvider,
GitHub: input,
Number: *input.Number,
Title: *input.Title,
State: *input.State,
Body: body,
URL: *input.HTMLURL,
RepoURL: *input.RepositoryURL,
URL: strings.Replace(*input.HTMLURL, "/pull/", "/issues/", -1),
RepoURL: strings.Join(parts[0:len(parts)-2], "/"),
Labels: make([]*IssueLabel, 0),
Assignees: make([]*Profile, 0),
}
Expand Down Expand Up @@ -239,6 +240,12 @@ func (i Issue) GetRelativeIssueURL(target string) string {
return target
}

if target[0] == '#' {
return fmt.Sprintf("%s/issues/%s", i.RepoURL, target[1:])
}

//target = strings.Replace(target, "#", "issues/", -1)

u, err := url.Parse(target)
if err != nil {
return ""
Expand All @@ -248,7 +255,7 @@ func (i Issue) GetRelativeIssueURL(target string) string {
path = i.Path()
}

return fmt.Sprintf("%s%s/issues/%s", i.ProviderURL(), path, u.Fragment)
return fmt.Sprintf("%s/%s/issues/%s", i.ProviderURL(), path, u.Fragment)
}

func (i Issue) BlocksAnEpic() bool {
Expand Down Expand Up @@ -360,9 +367,9 @@ func (i Issue) AddNodeToGraph(g *gographviz.Graph, parent string) error {

func (issues Issues) prepare() error {
var (
dependsOnRegex, _ = regexp.Compile(`(?i)(require|requires|blocked by|block by|depend on|depends on|parent of) ([a-z0-9:/_.-]+|[a-z0-9/_-]*#[0-9]+)`)
blocksRegex, _ = regexp.Compile(`(?i)(blocks|block|address|addresses|part of|child of|fix|fixes) ([a-z0-9:/_.-]+|[a-z0-9/_-]*#[0-9]+)`)
isDuplicateRegex, _ = regexp.Compile(`(?i)(duplicates|duplicate|dup of|dup|duplicate of) ([a-z0-9:/_.-]+|[a-z0-9/_-]*#[0-9]+)`)
dependsOnRegex, _ = regexp.Compile(`(?i)(require|requires|blocked by|block by|depend on|depends on|parent of) ([a-z0-9:/_.-]+#[0-9]+|[a-z0-9/_-]*#[0-9]+)`)
blocksRegex, _ = regexp.Compile(`(?i)(blocks|block|address|addresses|part of|child of|fix|fixes) ([a-z0-9:/_.-]+#[0-9]+|[a-z0-9/_-]*#[0-9]+)`)
isDuplicateRegex, _ = regexp.Compile(`(?i)(duplicates|duplicate|dup of|dup|duplicate of) ([a-z0-9:/_.-]+#[0-9]+|[a-z0-9/_-]*#[0-9]+)`)
weightMultiplierRegex, _ = regexp.Compile(`(?i)(depviz.weight_multiplier[:= ]+)([0-9]+)`)
baseWeightRegex, _ = regexp.Compile(`(?i)(depviz.base_weight[:= ]+)([0-9]+)`)
hideFromRoadmapRegex, _ = regexp.Compile(`(?i)(depviz.hide_from_roadmap)`) // FIXME: use label
Expand Down Expand Up @@ -400,7 +407,6 @@ func (issues Issues) prepare() error {
for _, match := range dependsOnRegex.FindAllStringSubmatch(issue.Body, -1) {
num := issue.GetRelativeIssueURL(match[len(match)-1])
dep, found := issues[num]
//fmt.Println(issue.URL, num, found, match[len(match)-1])
if !found {
issue.Errors = append(issue.Errors, fmt.Errorf("parent %q not found", num))
continue
Expand Down

0 comments on commit eab47c5

Please sign in to comment.