Skip to content

Commit

Permalink
feat: add time management (#547)
Browse files Browse the repository at this point in the history
* feat: add time management
* style: fix lint
* fix: optimize use case regex & rename some stuff & check if time is defined in front
* fix: define const in pack
  • Loading branch information
MikaelVallenet authored Aug 3, 2022
1 parent 434050a commit fe428f3
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 114 deletions.
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Eugene Sysmanov <[email protected]>
Evgeny Sysmanov <[email protected]>
ImgBotApp <[email protected]>
ismael FALL <[email protected]>
Lucas Germano <[email protected]>
Manfred Touron <[email protected]>
Manfred Touron <[email protected]>
Mikatech <[email protected]>
moul-bot <[email protected]>
Renovate Bot <[email protected]>
1 change: 1 addition & 0 deletions api/dvmodel.proto
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ message Task {
int32 num_comments = 18 [(gogoproto.moretags) = "quad:\"schema:numComments,optional\""];
int32 num_upvotes = 19 [(gogoproto.moretags) = "quad:\"schema:numUpvotes,optional\""];
int32 num_downvotes = 20 [(gogoproto.moretags) = "quad:\"schema:numDownvotes,optional\""];
string estimated_duration = 21 [(gogoproto.moretags) = "quad:\"schema:estimated_duration,optional\""];

// relationships
string has_author = 100 [(gogoproto.moretags) = "quad:\"hasAuthor,optional\"", (gogoproto.casttype) = "github.com/cayleygraph/quad.IRI"];
Expand Down
6 changes: 3 additions & 3 deletions gen.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

264 changes: 156 additions & 108 deletions internal/dvmodel/dvmodel.pb.go

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion internal/githubprovider/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@ package githubprovider

import (
"fmt"
"regexp"

"github.com/cayleygraph/quad"
"github.com/google/go-github/v30/github"
"github.com/xhit/go-str2duration/v2"
"go.uber.org/zap"
"moul.io/depviz/v3/internal/dvmodel"
"moul.io/depviz/v3/internal/dvparser"
"moul.io/multipmuri"
"moul.io/multipmuri/pmbodyparser"
)

const (
InvalidDuration string = "invalid"
UndefinedDuration string = "undefined"
)

func fromIssues(issues []*github.Issue, logger *zap.Logger) dvmodel.Batch {
batch := dvmodel.Batch{}
for _, issue := range issues {
Expand Down Expand Up @@ -48,6 +55,7 @@ func fromIssue(batch *dvmodel.Batch, input *github.Issue) error {
NumUpvotes: int32(*input.Reactions.PlusOne),
NumDownvotes: int32(*input.Reactions.MinusOne),
}
issue.EstimatedDuration = parseDuration(issue.Description)
if input.PullRequestLinks != nil { // is PR
issue.Kind = dvmodel.Task_MergeRequest
} else { // is issue
Expand Down Expand Up @@ -139,11 +147,23 @@ func fromIssue(batch *dvmodel.Batch, input *github.Issue) error {
return fmt.Errorf("unsupported pmbodyparser.Kind: %v", relationship.Kind)
}
}

batch.Tasks = append(batch.Tasks, &issue)
return nil
}

func parseDuration(body string) string {
compile := regexp.MustCompile(`time[ \t]+([w|d|h|m|0-9]+)`)
match := compile.FindStringSubmatch(body)
if len(match) < 2 || len(match[1]) == 0 {
return UndefinedDuration
}
_, err := str2duration.ParseDuration(match[1])
if err != nil {
return InvalidDuration
}
return match[1]
}

func fromUser(batch *dvmodel.Batch, input *github.User) (*dvmodel.Owner, error) {
entity, err := dvparser.ParseTarget(input.GetHTMLURL())
if err != nil {
Expand Down
11 changes: 9 additions & 2 deletions web/src/ui/Visualizer/renderers/GraphCard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import { renderToStaticMarkup } from 'react-dom/server'
import Issue from '../../components/icons/Issue'
import Hourglass from '../../components/icons/Hourglass'
import Pr from '../../components/icons/Pr'
import Comments from '../../components/icons/Comments'
import Github from '../../components/icons/Github'
Expand All @@ -24,7 +25,8 @@ const GraphCard = (data, type) => {
default:
break
}

let estimatedDuration = ""
if (data.estimated_duration !== undefined && data.estimated_duration !== "undefined") { estimatedDuration = data.estimated_duration}
const cardTemplate = (
<div id={data.html_id} className={`cy-card issue ${cardClasses}`}>
<div className="b-left">
Expand All @@ -37,7 +39,7 @@ const GraphCard = (data, type) => {
<div className="cy-icon icon-comments">
<Comments />
</div>
<div className="cy-icon icon-github">
<div className="cy-icon icon-hourglass">
<Github />
</div>
<div className="cy-icon avatar" />
Expand All @@ -47,6 +49,11 @@ const GraphCard = (data, type) => {
<div className="title">
{data.title.replace(/"/gi, '\'')}
</div>
{estimatedDuration && (
<div className="estimated-time">
<Hourglass/>{" "}{estimatedDuration}
</div>
)}
</div>
{/*
<div class='b-body-bottom'>
Expand Down
6 changes: 6 additions & 0 deletions web/src/ui/Visualizer/renderers/card.scss
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@
width: 405px;
display: block;
}
.estimated-time {
font-size: 18px;
line-height: 25px;
height: 105px;
width: 405px;
}
.b-body-top {
margin-bottom: 15px;
position: relative;
Expand Down
26 changes: 26 additions & 0 deletions web/src/ui/components/icons/Hourglass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react'

const HourglassIcon = () => (
<svg width="32px" height="32px" viewBox="0 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg">
<defs>
<rect x="0" y="0" width="478" height="255" rx="15" />
<filter x="-4.8%" y="-7.5%" width="109.6%" height="118.0%" filterUnits="objectBoundingBox">
<feMorphology radius="1" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1" />
<feOffset dx="0" dy="4" in="shadowSpreadOuter1" result="shadowOffsetOuter1" />
<feGaussianBlur stdDeviation="6" in="shadowOffsetOuter1" result="shadowBlurOuter1" />
<feColorMatrix values="0 0 0 0 0.219607843 0 0 0 0 0.231372549 0 0 0 0 0.384313725 0 0 0 0.15 0" type="matrix" in="shadowBlurOuter1" />
</filter>
</defs>
<g stroke="none" strokeWidth="1" fill="none" fillRule="evenodd">
<g transform="translate(-346.000000, -22.000000)">
<g transform="translate(62.000000, 21.000000)" fill="#DFE0EB" fillRule="nonzero">
<g className="icon-hourglass" transform="translate(284.000000, 1.000000)">
<path d="M22.781 16c4.305-2.729 7.219-7.975 7.219-14 0-0.677-0.037-1.345-0.109-2h-27.783c-0.072 0.655-0.109 1.323-0.109 2 0 6.025 2.914 11.271 7.219 14-4.305 2.729-7.219 7.975-7.219 14 0 0.677 0.037 1.345 0.109 2h27.783c0.072-0.655 0.109-1.323 0.109-2 0-6.025-2.914-11.271-7.219-14zM5 30c0-5.841 2.505-10.794 7-12.428v-3.143c-4.495-1.634-7-6.587-7-12.428v0h22c0 5.841-2.505 10.794-7 12.428v3.143c4.495 1.634 7 6.587 7 12.428h-22zM19.363 20.925c-2.239-1.27-2.363-2.918-2.363-3.918v-2.007c0-1 0.119-2.654 2.367-3.927 1.203-0.699 2.244-1.761 3.033-3.073h-12.799c0.79 1.313 1.832 2.376 3.036 3.075 2.239 1.27 2.363 2.918 2.363 3.918v2.007c0 1-0.119 2.654-2.367 3.927-2.269 1.318-3.961 3.928-4.472 7.073h15.677c-0.511-3.147-2.204-5.758-4.475-7.075z"></path>
</g>
</g>
</g>
</g>
</svg>
)

export default HourglassIcon

0 comments on commit fe428f3

Please sign in to comment.