Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
redmine_v2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
VeNtura
redmine_v2
Commits
1735d895
Commit
1735d895
authored
Dec 07, 2023
by
Tấn Trần Thanh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
50% for coding
parent
679e4d78
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
46 additions
and
28 deletions
+46
-28
plugins/workflow_report/app/controllers/workflow_report_controller.rb
+3
-3
plugins/workflow_report/app/models/workflow_report_custom_value.rb
+3
-0
plugins/workflow_report/app/models/workflow_report_issue.rb
+7
-4
plugins/workflow_report/app/models/workflow_report_version.rb
+3
-0
plugins/workflow_report/lib/workflow_report.rb
+30
-21
No files found.
plugins/workflow_report/app/controllers/workflow_report_controller.rb
View file @
1735d895
...
@@ -45,9 +45,9 @@ class WorkflowReportController < ApplicationController
...
@@ -45,9 +45,9 @@ class WorkflowReportController < ApplicationController
def
export
def
export
team
=
params
[
:team
]
team
=
params
[
:team
]
project_ids
=
$workflow_report_config
[
'teams'
].
select
{
|
hash
|
hash
.
key?
(
team
)
}[
0
][
team
]
project_ids
=
$workflow_report_config
[
'teams'
].
select
{
|
hash
|
hash
.
key?
(
team
)
}[
0
][
team
]
result
=
Rails
.
cache
.
fetch
(
"
#{
team
}
_
#{
params
[
:year
]
}
_
#{
params
[
:month
]
}
"
,
expires_in:
1
.
hours
)
do
#
result = Rails.cache.fetch("#{team}_#{params[:year]}_#{params[:month]}", expires_in: 1.hours) do
WorkflowReport
.
build_report
(
params
[
:year
].
to_i
,
params
[
:month
].
to_i
,
project_ids
)
result
=
WorkflowReport
.
build_report
(
params
[
:year
].
to_i
,
params
[
:month
].
to_i
,
project_ids
)
end
#
end
respond_to
do
|
format
|
respond_to
do
|
format
|
format
.
js
{
render
'build_table'
,
locals:
{
result:
result
[
:workflow_report
],
error_links:
result
[
:error_links
],
thead:
TABLE_HEADER
}
}
format
.
js
{
render
'build_table'
,
locals:
{
result:
result
[
:workflow_report
],
error_links:
result
[
:error_links
],
thead:
TABLE_HEADER
}
}
end
end
...
...
plugins/workflow_report/app/models/workflow_report_custom_value.rb
0 → 100644
View file @
1735d895
class
WorkflowReportCustomValue
<
CustomValue
belongs_to
:workflow_report_issue
,
class_name:
'WorkflowReportCustomValue'
,
foreign_key:
'custom_field_id'
end
plugins/workflow_report/app/models/workflow_report_issue.rb
View file @
1735d895
...
@@ -6,14 +6,17 @@ class WorkflowReportIssue < Issue
...
@@ -6,14 +6,17 @@ class WorkflowReportIssue < Issue
PR_FIELD_ID
=
18
PR_FIELD_ID
=
18
JP_REQUEST_FIELD_ID
=
16
JP_REQUEST_FIELD_ID
=
16
belongs_to
:workflow_report_version
,
class_name:
'Version'
,
foreign_key:
'fixed_version_id'
has_many
:workflow_report_custom_values
,
class_name:
'WorkflowReportCustomValue'
,
foreign_key:
'customized_id'
scope
:find_root_ids
,
->
(
year
,
month
,
project_ids
)
{
scope
:find_root_ids
,
->
(
year
,
month
,
project_ids
)
{
joins
(
:project
,
project: :enabled_modules
)
includes
(
:project
,
:workflow_report_version
,
:workflow_report_custom_values
,
:time_entries
,
:status
,
project: :enabled_modules
)
.
joins
(
'LEFT OUTER JOIN time_entries ON issues.id = time_entries.issue_id'
)
.
where
.
not
(
projects:
{
status:
9
},
issues:
{
tracker_id:
1
}
)
.
where
.
not
(
projects:
{
status:
9
}
)
.
where
(
root_id:
59050
)
.
where
(
projects:
{
id:
project_ids
},
enabled_modules:
{
name:
'time_tracking'
})
.
where
(
projects:
{
id:
project_ids
},
enabled_modules:
{
name:
'time_tracking'
})
.
where
([
'((time_entries.spent_on IS NOT NULL AND time_entries.tyear = ? AND time_entries.tmonth = ?) OR (issues.closed_on BETWEEN ? AND ?))'
,
.
where
([
'((time_entries.spent_on IS NOT NULL AND time_entries.tyear = ? AND time_entries.tmonth = ?) OR (issues.closed_on BETWEEN ? AND ?))'
,
year
,
month
,
DateTime
.
new
(
year
,
month
).
beginning_of_day
,
DateTime
.
new
(
year
,
month
,
-
1
).
end_of_day
])
year
,
month
,
DateTime
.
new
(
year
,
month
).
beginning_of_day
,
DateTime
.
new
(
year
,
month
,
-
1
).
end_of_day
])
.
distinct
.
pluck
(
:root_id
)
.
order
(
:root_id
)
}
}
scope
:find_sum_hours_records
,
->
(
root_ids
)
{
scope
:find_sum_hours_records
,
->
(
root_ids
)
{
...
...
plugins/workflow_report/app/models/workflow_report_version.rb
0 → 100644
View file @
1735d895
class
WorkflowReportVersion
<
Version
has_many
:workflow_report_issues
,
foreign_key:
'fixed_version_id'
end
plugins/workflow_report/lib/workflow_report.rb
View file @
1735d895
...
@@ -13,24 +13,23 @@ module WorkflowReport
...
@@ -13,24 +13,23 @@ module WorkflowReport
github
=
Github
.
new
oauth_token:
$workflow_report_config
[
'github_token'
]
github
=
Github
.
new
oauth_token:
$workflow_report_config
[
'github_token'
]
error_links
=
[]
error_links
=
[]
result
=
TABLE_HEADER
.
length
.
times
.
map
{
[]
}
result
=
TABLE_HEADER
.
length
.
times
.
map
{
[]
}
r
oot_id
s
=
WorkflowReportIssue
.
find_root_ids
(
year
,
month
,
project_ids
)
r
aw_task
s
=
WorkflowReportIssue
.
find_root_ids
(
year
,
month
,
project_ids
)
return
{
workflow_report:
[],
error_links:
[]
}
if
r
oot_id
s
.
empty?
return
{
workflow_report:
[],
error_links:
[]
}
if
r
aw_task
s
.
empty?
sum_hours_records
=
WorkflowReportIssue
.
find_sum_hours_records
(
root_ids
)
#
sum_hours_records = WorkflowReportIssue.find_sum_hours_records(root_ids)
raw_tasks
=
WorkflowReportIssue
.
raw_tasks_records
(
root_ids
)
#
raw_tasks = WorkflowReportIssue.raw_tasks_records(root_ids)
raw_tasks
.
group_by
(
&
:root_id
).
each
do
|
root_id
,
record
|
raw_tasks
.
group_by
(
&
:root_id
).
each
do
|
root_id
,
record
|
sum_hours_record
=
sum_hours_records
.
find
{
|
hr
|
hr
.
root_id
==
root_id
}
issue_ids
=
record
.
map
(
&
:id
)
issue_ids
=
record
.
map
(
&
:id
)
sum_hours_record
=
record
.
first
.
time_entries
.
all
journals
=
WorkflowReportJournal
.
find_journal_by_issue_ids
(
issue_ids
).
to_a
journals
=
WorkflowReportJournal
.
find_journal_by_issue_ids
(
issue_ids
).
to_a
result
[
0
]
<<
root_id
result
[
0
]
<<
root_id
result
[
1
]
<<
record
.
first
[
:project
]
.
gsub
(
/[^[:print:]]/
,
''
)
result
[
1
]
<<
record
.
first
.
project
.
name
.
gsub
(
/[^[:print:]]/
,
''
)
result
[
2
]
<<
record
.
first
[
:subject
].
gsub
(
/[^[:print:]]/
,
''
)
result
[
2
]
<<
record
.
first
[
:subject
].
gsub
(
/[^[:print:]]/
,
''
)
result
[
3
]
<<
record
.
first
[
:target_version
]
result
[
3
]
<<
record
.
first
.
workflow_report_version
.
name
issue_created_on
=
record
.
min_by
{
|
i
|
i
[
:created_on
]
if
i
[
:created_on
].
present?
}
issue_created_on
=
record
.
min_by
{
|
i
|
i
[
:created_on
]
if
i
[
:created_on
].
present?
}
result
[
4
].
push
(
issue_created_on
.
present?
?
issue_created_on
[:
created_on
]
&
.
strftime
(
'%Y-%m-%d %H:%M:%S'
)
:
''
)
result
[
4
].
push
(
issue_created_on
.
present?
?
issue_created_on
.
created_on
&
.
strftime
(
'%Y-%m-%d %H:%M:%S'
)
:
''
)
closed_on_issues
=
record
.
map
(
&
:closed_on
).
compact
closed_on_issues
=
record
.
map
(
&
:closed_on
).
compact
issue_closed_on
=
closed_on_issues
.
max_by
{
|
close_on
|
close_on
}
issue_closed_on
=
closed_on_issues
.
max_by
{
|
close_on
|
close_on
}
result
[
5
].
push
(
issue_closed_on
.
present?
?
issue_closed_on
.
strftime
(
'%Y-%m-%d %H:%M:%S'
)
:
''
)
result
[
5
].
push
(
issue_closed_on
.
present?
?
issue_closed_on
.
strftime
(
'%Y-%m-%d %H:%M:%S'
)
:
''
)
...
@@ -39,12 +38,13 @@ module WorkflowReport
...
@@ -39,12 +38,13 @@ module WorkflowReport
issue_due_date
=
issue_due_dates
.
max_by
{
|
due_date
|
due_date
}
issue_due_date
=
issue_due_dates
.
max_by
{
|
due_date
|
due_date
}
result
[
6
].
push
(
issue_due_date
.
present?
?
issue_due_date
&
.
strftime
(
'%Y-%m-%d %H:%M:%S'
)
:
''
)
result
[
6
].
push
(
issue_due_date
.
present?
?
issue_due_date
&
.
strftime
(
'%Y-%m-%d %H:%M:%S'
)
:
''
)
result
[
7
].
push
(
record
.
first
[
:status
].
present?
?
record
.
first
[:
status
]
:
''
)
result
[
7
].
push
(
record
.
first
.
status
.
name
.
present?
?
record
.
first
.
status
.
name
:
''
)
sum_estimated_hours
=
record
.
map
{
|
i
|
i
[
:estimated_hours
]
}.
compact
.
sum
sum_estimated_hours
=
record
.
map
{
|
i
|
i
.
estimated_hours
}.
compact
.
sum
result
[
8
]
<<
sum_estimated_hours
result
[
8
]
<<
sum_estimated_hours
if
sum_hours_record
.
present?
actual_time
=
record
.
map
{
|
item
|
item
.
time_entries
.
all
.
map
(
&
:hours
).
sum
}.
sum
result
[
9
]
<<
sum_hours_record
[
:hours
]
if
actual_time
.
present?
result
[
10
]
<<
(
sum_hours_record
[
:hours
]
-
sum_estimated_hours
)
result
[
9
]
<<
actual_time
result
[
10
]
<<
(
actual_time
-
sum_estimated_hours
)
else
else
result
[
9
]
<<
''
result
[
9
]
<<
''
result
[
10
]
<<
''
result
[
10
]
<<
''
...
@@ -62,10 +62,14 @@ module WorkflowReport
...
@@ -62,10 +62,14 @@ module WorkflowReport
end
end
pull_request
=
''
pull_request
=
''
jp_request
=
''
jp_request
=
''
test_case
=
0
staging_bug
=
0
jp_bug
=
0
proc_bug
=
0
record
.
each
do
|
issue
|
record
.
each
do
|
issue
|
if
issue
.
tracker_id
==
12
if
issue
.
tracker_id
==
12
pull_request
=
issue
.
pr
pull_request
=
issue
.
custom_values
.
find_by
(
custom_field_id:
18
).
value
jp_request
=
issue
.
jp_request
jp_request
=
issue
.
custom_values
.
find_by
(
custom_field_id:
16
).
value
end
end
process
=
get_process
(
issue
.
subject
.
gsub
(
/[^[:print:]]/
,
''
))
process
=
get_process
(
issue
.
subject
.
gsub
(
/[^[:print:]]/
,
''
))
...
@@ -83,15 +87,20 @@ module WorkflowReport
...
@@ -83,15 +87,20 @@ module WorkflowReport
build_est_to_actual_time!
(
result
,
EST_DETAIL_FIRST_COL
,
issue
.
estimated_hours
.
to_f
,
6
)
build_est_to_actual_time!
(
result
,
EST_DETAIL_FIRST_COL
,
issue
.
estimated_hours
.
to_f
,
6
)
build_est_to_actual_time!
(
result
,
ACTUAL_TIME_DETAIL_FIRST_COL
,
issue
.
spent_hours
.
to_f
,
6
)
build_est_to_actual_time!
(
result
,
ACTUAL_TIME_DETAIL_FIRST_COL
,
issue
.
spent_hours
.
to_f
,
6
)
end
end
test
=
issue
.
custom_values
.
where
(
custom_field_id:
22
)
end
end
if
sum_hours_record
.
nil?
if
sum_hours_record
.
nil?
# testcases, internal bug, stg bug, prod bug
# testcases, internal bug, stg bug, prod bug
(
28
..
31
).
each
{
|
i
|
result
[
i
]
<<
''
}
(
28
..
31
).
each
{
|
i
|
result
[
i
]
<<
''
}
else
else
byebug
a
=
record
.
select
{
|
item
|
p
item
.
custom_values
.
where
(
'custom_field_id= 22'
).
length
!=
0
}
# testcases, internal bug, stg bug, prod bug
# testcases, internal bug, stg bug, prod bug
BUGS
.
each
do
|
status
,
column
|
# BUGS.each do |status, column|
result
[
column
].
push
(
sum_hours_record
[
status
].
to_i
>=
0
?
sum_hours_record
[
status
]
:
''
)
# rs = record.map { |item| item.time_entries.all.map(&:hours).sum }.sum
end
# result[column].push(sum_hours_record[status].to_i >= 0 ? sum_hours_record[status] : '')
# end
end
end
if
jp_request
.
present?
if
jp_request
.
present?
jp_request
=
jp_request
.
strip
jp_request
=
jp_request
.
strip
...
@@ -111,7 +120,7 @@ module WorkflowReport
...
@@ -111,7 +120,7 @@ module WorkflowReport
result
[
33
]
<<
''
result
[
33
]
<<
''
end
end
# pr detail
# pr detail
pr
=
{
pr_comments:
0
,
pr_review_comments:
0
,
pr_commits:
0
,
pr_
additions:
0
,
pr_deletions:
0
,
pr_changed_file
s:
0
}
pr
=
{
pr_comments:
0
,
pr_review_comments:
0
,
pr_commits:
0
,
pr_
changed_files:
0
,
pr_additions:
0
,
pr_deletion
s:
0
}
if
pull_request
.
present?
if
pull_request
.
present?
prs
=
pull_request
.
split
(
"
\r\n
"
).
compact
prs
=
pull_request
.
split
(
"
\r\n
"
).
compact
...
@@ -125,9 +134,9 @@ module WorkflowReport
...
@@ -125,9 +134,9 @@ module WorkflowReport
pr
[
:pr_comments
]
+=
pr_detail
.
comments
pr
[
:pr_comments
]
+=
pr_detail
.
comments
pr
[
:pr_review_comments
]
+=
pr_detail
.
review_comments
pr
[
:pr_review_comments
]
+=
pr_detail
.
review_comments
pr
[
:pr_commits
]
+=
pr_detail
.
commits
pr
[
:pr_commits
]
+=
pr_detail
.
commits
pr
[
:pr_changed_files
]
+=
pr_detail
.
changed_files
pr
[
:pr_additions
]
+=
pr_detail
.
additions
pr
[
:pr_additions
]
+=
pr_detail
.
additions
pr
[
:pr_deletions
]
+=
pr_detail
.
deletions
pr
[
:pr_deletions
]
+=
pr_detail
.
deletions
pr
[
:pr_changed_files
]
+=
pr_detail
.
changed_files
end
end
rescue
=>
e
rescue
=>
e
error_links
<<
"#
#{
root_id
}
Error occurred during the build with the PR link:
\r\n
-
#{
link
}
\r\n
-
#{
e
.
message
.
gsub
(
/(?<=access_token=).*/
,
'123'
)
}
"
error_links
<<
"#
#{
root_id
}
Error occurred during the build with the PR link:
\r\n
-
#{
link
}
\r\n
-
#{
e
.
message
.
gsub
(
/(?<=access_token=).*/
,
'123'
)
}
"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment