Skip to content

Commit

Permalink
fix: outdated SQL queries due to PR status changes (apache#4548)
Browse files Browse the repository at this point in the history
* fix: qutdated SQL queries due to PR status changes

* fix: github pr e2e failed

* fix: update dashboard

* fix: update dashboard
  • Loading branch information
abeizn authored Mar 1, 2023
1 parent 0467a4d commit 78bf4f9
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 132 deletions.

Large diffs are not rendered by default.

98 changes: 49 additions & 49 deletions backend/plugins/github/e2e/snapshot_tables/pull_requests.csv

Large diffs are not rendered by default.

16 changes: 15 additions & 1 deletion backend/plugins/github/tasks/pr_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,18 @@ package tasks

import (
"encoding/json"
"regexp"

"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/plugin"
"github.com/apache/incubator-devlake/helpers/pluginhelper/api"
"github.com/apache/incubator-devlake/plugins/github/models"
"regexp"
)

const (
OPEN = "OPEN"
CLOSED = "CLOSED"
MERGED = "MERGED"
)

var ExtractApiPullRequestsMeta = plugin.SubTaskMeta{
Expand Down Expand Up @@ -182,6 +189,13 @@ func convertGithubPullRequest(pull *GithubApiPullRequest, connId uint64, repoId
if pull.Head.Repo != nil {
githubPull.HeadRepoId = pull.Head.Repo.GithubId
}
if pull.State == "open" {
githubPull.State = OPEN
} else if pull.State == "closed" && pull.MergedAt != nil {
githubPull.State = MERGED
} else {
githubPull.State = CLOSED
}

return githubPull, nil
}
13 changes: 7 additions & 6 deletions grafana/dashboards/ContributorExperience.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"id": 11,
"iteration": 1672981230078,
"id": 21,
"iteration": 1677590412757,
"links": [],
"panels": [
{
Expand Down Expand Up @@ -508,7 +508,7 @@
"metricColumn": "none",
"queryType": "randomWalk",
"rawQuery": true,
"rawSql": "select\n\tavg(TIMESTAMPDIFF(Minute,created_date,closed_date)/1440) as time_to_close\nfrom \n\tpull_requests pr\nwhere \n date(created_date) BETWEEN\n curdate() - INTERVAL DAYOFMONTH(curdate())-1 DAY - INTERVAL 1 month and\n curdate() - INTERVAL DAYOFMONTH(curdate()) DAY\n\tand status = 'closed'\n\tand pr.base_repo_id in ($repo_id)\n\n\n",
"rawSql": "select\n\tavg(TIMESTAMPDIFF(Minute,created_date,closed_date)/1440) as time_to_close\nfrom \n\tpull_requests pr\nwhere \n date(created_date) BETWEEN\n curdate() - INTERVAL DAYOFMONTH(curdate())-1 DAY - INTERVAL 1 month and\n curdate() - INTERVAL DAYOFMONTH(curdate()) DAY\n\tand status in ('closed', 'merged', 'declined')\n\tand pr.base_repo_id in ($repo_id)\n\n\n",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -590,7 +590,7 @@
"metricColumn": "none",
"queryType": "randomWalk",
"rawQuery": true,
"rawSql": "select\n 100 * sum(case when TIMESTAMPDIFF(Minute, created_date, closed_date) / 1440 < $prrt_sla then 1 else null end) / count(*)\nfrom \n\tpull_requests pr\nwhere \n date(created_date) BETWEEN\n curdate() - INTERVAL DAYOFMONTH(curdate())-1 DAY - INTERVAL 1 month and\n curdate() - INTERVAL DAYOFMONTH(curdate()) DAY\n\tand status = 'closed'\n\tand pr.base_repo_id in ($repo_id)\n\n\n",
"rawSql": "select\n 100 * sum(case when TIMESTAMPDIFF(Minute, created_date, closed_date) / 1440 < $prrt_sla then 1 else null end) / count(*)\nfrom \n\tpull_requests pr\nwhere \n date(created_date) BETWEEN\n curdate() - INTERVAL DAYOFMONTH(curdate())-1 DAY - INTERVAL 1 month and\n curdate() - INTERVAL DAYOFMONTH(curdate()) DAY\n\tand status in ('closed', 'merged', 'declined')\n\tand pr.base_repo_id in ($repo_id)\n\n\n",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -672,7 +672,7 @@
"metricColumn": "none",
"queryType": "randomWalk",
"rawQuery": true,
"rawSql": "select\n 100 * count(distinct case when status = 'closed' and merged_date is null then id else null end)/count(distinct case when status = 'closed' then id else null end) as ratio\nfrom \n\tpull_requests pr\nwhere\n date(created_date) BETWEEN\n curdate() - INTERVAL DAYOFMONTH(curdate())-1 DAY - INTERVAL 1 month and\n curdate() - INTERVAL DAYOFMONTH(curdate()) DAY\n and pr.base_repo_id in ($repo_id)",
"rawSql": "select\n 100 * count(distinct case when status in ('closed', 'merged', 'declined') and merged_date is null then id else null end)/count(distinct case when status in ('closed', 'merged', 'declined') then id else null end) as ratio\nfrom \n\tpull_requests pr\nwhere\n date(created_date) BETWEEN\n curdate() - INTERVAL DAYOFMONTH(curdate())-1 DAY - INTERVAL 1 month and\n curdate() - INTERVAL DAYOFMONTH(curdate()) DAY\n and pr.base_repo_id in ($repo_id)",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -722,6 +722,7 @@
"type": "text"
}
],
"refresh": "",
"schemaVersion": 30,
"style": "dark",
"tags": [],
Expand Down Expand Up @@ -827,5 +828,5 @@
"timezone": "",
"title": "Contributor Experience",
"uid": "bwsP5Nz4z",
"version": 2
"version": 6
}
10 changes: 3 additions & 7 deletions grafana/dashboards/EngineeringThroughputAndCycleTime.json
Original file line number Diff line number Diff line change
Expand Up @@ -1555,13 +1555,9 @@
{
"allValue": null,
"current": {
"selected": true,
"text": [
"Louis"
],
"value": [
"Louis"
]
"selected": false,
"text": "All",
"value": "$__all"
},
"datasource": "mysql",
"definition": "select distinct name from projects",
Expand Down
20 changes: 10 additions & 10 deletions grafana/dashboards/GitHub.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"id": 3,
"iteration": 1672983056105,
"id": 25,
"iteration": 1677590489731,
"links": [],
"panels": [
{
Expand Down Expand Up @@ -1164,7 +1164,7 @@
"hide": false,
"metricColumn": "none",
"rawQuery": true,
"rawSql": "select\n author_name,\n\tcount(*) as merged_pull_request_count\nfrom \n\tpull_requests pr\nwhere\n $__timeFilter(created_date)\n\tand base_repo_id in ($repo_id)\n\tand status = \"closed\"\n\tand merged_date is not null\ngroup by 1\norder by 2 desc\nlimit 20\n",
"rawSql": "select\n author_name,\n\tcount(*) as merged_pull_request_count\nfrom \n\tpull_requests pr\nwhere\n $__timeFilter(created_date)\n\tand base_repo_id in ($repo_id)\n and pr.status in ('closed', 'merged', 'declined') and pr.merged_date is not null\ngroup by 1\norder by 2 desc\nlimit 20\n",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -1259,7 +1259,7 @@
"hide": false,
"metricColumn": "none",
"rawQuery": true,
"rawSql": "select\n count(distinct case when status = 'closed' and merged_date is null then id else null end)/count(distinct case when status = 'closed' then id else null end) as ratio\nfrom \n\tpull_requests pr\nwhere\n $__timeFilter(created_date)\n\tand base_repo_id in ($repo_id)",
"rawSql": "select\n count(distinct case when status in ('closed', 'merged') and merged_date is not null then id else null end)/count(distinct case when status in ('closed', 'merged') then id else null end) as ratio\nfrom \n\tpull_requests pr\nwhere\n $__timeFilter(created_date)\n\tand base_repo_id in ($repo_id)",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -1362,7 +1362,7 @@
"hide": false,
"metricColumn": "none",
"rawQuery": true,
"rawSql": "SELECT\n DATE_ADD(date(created_date), INTERVAL -DAYOFMONTH(date(created_date))+1 DAY) as time,\n count(distinct case when status != 'closed' then id else null end) as \"PR: Open\",\n count(distinct case when status = 'closed' and merged_date is null then id else null end) as \"PR: Closed without merging\",\n count(distinct case when status = 'closed' and merged_date is not null then id else null end) as \"PR: Closed and merged\"\nFROM pull_requests\nWHERE\n $__timeFilter(created_date)\n and created_date >= DATE_ADD(DATE_ADD($__timeFrom(), INTERVAL -DAY($__timeFrom())+1 DAY), INTERVAL +1 MONTH)\n and base_repo_id in ($repo_id)\ngroup by 1\n",
"rawSql": "SELECT\n DATE_ADD(date(created_date), INTERVAL -DAYOFMONTH(date(created_date))+1 DAY) as time,\n count(distinct case when status != 'closed' then id else null end) as \"PR: Open\",\n count(distinct case when status in ('closed', 'merged') and merged_date is null then id else null end) as \"PR: Closed without merging\",\n count(distinct case when status in ('closed', 'merged') then id else null end) as \"PR: Closed and merged\"\nFROM pull_requests\nWHERE\n $__timeFilter(created_date)\n and created_date >= DATE_ADD(DATE_ADD($__timeFrom(), INTERVAL -DAY($__timeFrom())+1 DAY), INTERVAL +1 MONTH)\n and base_repo_id in ($repo_id)\ngroup by 1\n",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -1444,7 +1444,7 @@
"hide": false,
"metricColumn": "none",
"rawQuery": true,
"rawSql": "select\n\tcount(*) as merged_pull_request_count\nfrom \n\tpull_requests pr\nwhere\n $__timeFilter(created_date)\n\tand base_repo_id in ($repo_id)\n\tand status = \"closed\"\n\tand merged_date is null",
"rawSql": "select\n\tcount(*) as merged_pull_request_count\nfrom \n\tpull_requests pr\nwhere\n $__timeFilter(created_date)\n\tand base_repo_id in ($repo_id)\n\tand pr.status in ('closed', 'merged') and pr.merged_date is null",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -1549,7 +1549,7 @@
"hide": false,
"metricColumn": "none",
"rawQuery": true,
"rawSql": "SELECT\n DATE_ADD(date(created_date), INTERVAL -DAYOFMONTH(date(created_date))+1 DAY) as time,\n count(distinct case when status = 'closed' and merged_date is null then id else null end)/count(distinct case when status = 'closed' then id else null end) as ratio\nFROM pull_requests\nWHERE\n $__timeFilter(created_date)\n and base_repo_id in ($repo_id)\ngroup by 1\n",
"rawSql": "SELECT\n DATE_ADD(date(created_date), INTERVAL -DAYOFMONTH(date(created_date))+1 DAY) as time,\n count(distinct case when status in ('closed', 'merged') and merged_date is null then id else null end)/count(distinct case when status in ('closed', 'merged') then id else null end) as ratio\nFROM pull_requests\nWHERE\n $__timeFilter(created_date)\n and base_repo_id in ($repo_id)\ngroup by 1\n",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -1808,7 +1808,7 @@
"hide": false,
"metricColumn": "none",
"rawQuery": true,
"rawSql": "select\n\tavg(TIMESTAMPDIFF(Minute,created_date,closed_date)/1440) as time_to_close\nfrom \n\tpull_requests\nwhere \n $__timeFilter(created_date)\n\tand base_repo_id in ($repo_id)\n\tand status = 'closed'\n\n\n",
"rawSql": "select\n\tavg(TIMESTAMPDIFF(Minute,created_date,closed_date)/1440) as time_to_close\nfrom \n\tpull_requests\nwhere \n $__timeFilter(created_date)\n\tand base_repo_id in ($repo_id)\n\tand status in ('closed', 'merged')\n\n\n",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -1905,7 +1905,7 @@
"hide": false,
"metricColumn": "none",
"rawQuery": true,
"rawSql": "with _prs as(\n SELECT\n DATE_ADD(date(created_date), INTERVAL -DAY(date(created_date))+1 DAY) as time,\n avg(TIMESTAMPDIFF(Minute,created_date,closed_date)/1440) as time_to_close\n FROM pull_requests\n WHERE\n $__timeFilter(created_date)\n and created_date >= DATE_ADD(DATE_ADD($__timeFrom(), INTERVAL -DAY($__timeFrom())+1 DAY), INTERVAL +1 MONTH)\n and base_repo_id in ($repo_id)\n and status = 'closed'\n group by 1\n)\n\nSELECT \n date_format(time,'%M %Y') as month,\n time_to_close as \"Time to Close\"\nFROM _prs\nORDER BY time\n",
"rawSql": "with _prs as(\n SELECT\n DATE_ADD(date(created_date), INTERVAL -DAY(date(created_date))+1 DAY) as time,\n avg(TIMESTAMPDIFF(Minute,created_date,closed_date)/1440) as time_to_close\n FROM pull_requests\n WHERE\n $__timeFilter(created_date)\n and created_date >= DATE_ADD(DATE_ADD($__timeFrom(), INTERVAL -DAY($__timeFrom())+1 DAY), INTERVAL +1 MONTH)\n and base_repo_id in ($repo_id)\n and status in ('closed', 'merged')\n group by 1\n)\n\nSELECT \n date_format(time,'%M %Y') as month,\n time_to_close as \"Time to Close\"\nFROM _prs\nORDER BY time\n",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -1999,5 +1999,5 @@
"timezone": "",
"title": "GitHub",
"uid": "KXWvOFQnz",
"version": 2
"version": 10
}
20 changes: 10 additions & 10 deletions grafana/dashboards/Gitlab.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"editable": true,
"gnetId": null,
"graphTooltip": 0,
"id": 14,
"iteration": 1660820788891,
"id": 26,
"iteration": 1677590524546,
"links": [],
"panels": [
{
Expand Down Expand Up @@ -306,7 +306,7 @@
"hide": false,
"metricColumn": "none",
"rawQuery": true,
"rawSql": "select\n author_name,\n\tcount(*) as merged_pull_request_count\nfrom \n\tpull_requests pr\nwhere\n $__timeFilter(created_date)\n\tand base_repo_id in ($repo_id)\n\tand merged_date is not null\ngroup by 1\norder by 2 desc\nlimit 20\n",
"rawSql": "select\n author_name,\n\tcount(*) as merged_pull_request_count\nfrom \n\tpull_requests pr\nwhere\n $__timeFilter(created_date)\n\tand base_repo_id in ($repo_id)\n\tand pr.status in ('closed', 'merged') and pr.merged_date is not null\ngroup by 1\norder by 2 desc\nlimit 20\n",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -401,7 +401,7 @@
"hide": false,
"metricColumn": "none",
"rawQuery": true,
"rawSql": "select\n count(distinct case when status = 'closed' and merged_date is null then id else null end)/count(distinct case when status = 'closed' or merged_date is not null then id else null end) as ratio\nfrom \n\tpull_requests pr\nwhere\n $__timeFilter(created_date)\n\tand base_repo_id in ($repo_id)",
"rawSql": "select\n count(distinct case when status in ('closed', 'merged') and merged_date is null then id else null end)/count(distinct case when status in ('closed', 'merged') then id else null end) as ratio\nfrom \n\tpull_requests pr\nwhere\n $__timeFilter(created_date)\n\tand base_repo_id in ($repo_id)",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -504,7 +504,7 @@
"hide": false,
"metricColumn": "none",
"rawQuery": true,
"rawSql": "SELECT\n DATE_ADD(date(created_date), INTERVAL -DAYOFMONTH(date(created_date))+1 DAY) as time,\n count(distinct case when status not in ('closed','merged') then id else null end) as \"PR: Open\",\n count(distinct case when status = 'closed' and merged_date is null then id else null end) as \"PR: Closed without merging\",\n count(distinct case when merged_date is not null then id else null end) as \"PR: Merged\"\nFROM pull_requests\nWHERE\n $__timeFilter(created_date)\n and base_repo_id in ($repo_id)\ngroup by 1\n",
"rawSql": "SELECT\n DATE_ADD(date(created_date), INTERVAL -DAYOFMONTH(date(created_date))+1 DAY) as time,\n count(distinct case when status not in ('closed','merged') then id else null end) as \"PR: Open\",\n count(distinct case when status in ('closed', 'merged') and merged_date is null then id else null end) as \"PR: Closed without merging\",\n count(distinct case when status in ('closed', 'merged') and merged_date is not null then id else null end) as \"PR: Merged\"\nFROM pull_requests\nWHERE\n $__timeFilter(created_date)\n and base_repo_id in ($repo_id)\ngroup by 1\n",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -586,7 +586,7 @@
"hide": false,
"metricColumn": "none",
"rawQuery": true,
"rawSql": "select\n\tcount(*) as merged_pull_request_count\nfrom \n\tpull_requests pr\nwhere\n $__timeFilter(created_date)\n\tand base_repo_id in ($repo_id)\n\tand status = \"closed\"\n\tand merged_date is null",
"rawSql": "select\n\tcount(*) as merged_pull_request_count\nfrom \n\tpull_requests pr\nwhere\n $__timeFilter(created_date)\n\tand base_repo_id in ($repo_id)\n\tand pr.status in ('closed', 'merged') and pr.merged_date is null",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -693,7 +693,7 @@
"hide": false,
"metricColumn": "none",
"rawQuery": true,
"rawSql": "SELECT\n DATE_ADD(date(created_date), INTERVAL -DAYOFMONTH(date(created_date))+1 DAY) as time,\n count(distinct case when status = 'closed' and merged_date is null then id else null end)/count(distinct case when status = 'closed' or merged_date is not null then id else null end) as ratio\nFROM pull_requests\nWHERE\n $__timeFilter(created_date)\n and base_repo_id in ($repo_id)\ngroup by 1\n",
"rawSql": "SELECT\n DATE_ADD(date(created_date), INTERVAL -DAYOFMONTH(date(created_date))+1 DAY) as time,\n count(distinct case when status in ('closed', 'merged') and merged_date is null then id else null end)/count(distinct case when status in ('closed', 'merged') and merged_date is not null then id else null end) as ratio\nFROM pull_requests\nWHERE\n $__timeFilter(created_date)\n and base_repo_id in ($repo_id)\ngroup by 1\n",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -952,7 +952,7 @@
"hide": false,
"metricColumn": "none",
"rawQuery": true,
"rawSql": "select\n\tavg(TIMESTAMPDIFF(Minute,created_date,closed_date)/1440) as time_to_close\nfrom \n\tpull_requests\nwhere \n $__timeFilter(created_date)\n\tand base_repo_id in ($repo_id)\n\tand status = 'closed'\n\n\n",
"rawSql": "select\n\tavg(TIMESTAMPDIFF(Minute,created_date,closed_date)/1440) as time_to_close\nfrom \n\tpull_requests\nwhere \n $__timeFilter(created_date)\n\tand base_repo_id in ($repo_id)\n\tand status in ('closed', 'merged')\n\n\n",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -1049,7 +1049,7 @@
"hide": false,
"metricColumn": "none",
"rawQuery": true,
"rawSql": "with _prs as(\n SELECT\n DATE_ADD(date(created_date), INTERVAL -DAY(date(created_date))+1 DAY) as time,\n avg(TIMESTAMPDIFF(Minute,created_date,closed_date)/1440) as time_to_close\n FROM pull_requests\n WHERE\n $__timeFilter(created_date)\n and base_repo_id in ($repo_id)\n and status = 'closed'\n and created_date >= DATE_ADD(DATE_ADD($__timeFrom(), INTERVAL -DAY($__timeFrom())+1 DAY), INTERVAL +1 MONTH)\n group by 1\n)\n\nSELECT \n date_format(time,'%M %Y') as month,\n time_to_close as \"Time to Close\"\nFROM _prs\nORDER BY time\n",
"rawSql": "with _prs as(\n SELECT\n DATE_ADD(date(created_date), INTERVAL -DAY(date(created_date))+1 DAY) as time,\n avg(TIMESTAMPDIFF(Minute,created_date,closed_date)/1440) as time_to_close\n FROM pull_requests\n WHERE\n $__timeFilter(created_date)\n and base_repo_id in ($repo_id)\n and status in ('closed', 'merged')\n and created_date >= DATE_ADD(DATE_ADD($__timeFrom(), INTERVAL -DAY($__timeFrom())+1 DAY), INTERVAL +1 MONTH)\n group by 1\n)\n\nSELECT \n date_format(time,'%M %Y') as month,\n time_to_close as \"Time to Close\"\nFROM _prs\nORDER BY time\n",
"refId": "A",
"select": [
[
Expand Down Expand Up @@ -1143,5 +1143,5 @@
"timezone": "",
"title": "GitLab",
"uid": "msSjEq97z",
"version": 6
"version": 10
}

0 comments on commit 78bf4f9

Please sign in to comment.