grim/youtrack-import
Clone
Summary
Browse
Changes
Graph
Grab the distinct version and milestone fields from tickets as well
draft
default
tip
2020-09-07, Gary Kramlich
c3d30cb6d4ea
Grab the distinct version and milestone fields from tickets as well
package
trac
import
(
"database/sql"
"keep.imfreedom.org/grim/youtrack-import/youtrack"
)
type
version
struct
{
Name
string
`db:"name"`
Time
sql
.
NullInt64
`db:"time"`
Description
sql
.
NullString
`db:"description"`
}
func
(
e
*
environment
)
loadVersions
()
([]
youtrack
.
Version
,
error
)
{
versions
:=
[]
version
{}
// we grab the values from the version and the milestone tables as well as
// the distinct values for version and milestone from each ticket to figure
// out what version are all here. In the Pidgin trac, milestones were
// essentially the fix version so it makes sense.
err
:=
e
.
db
.
Select
(
&
versions
,
`
SELECT y.name, coalesce(y.time,0) AS time, y.description
FROM (
SELECT x.name, x.time, x.description, row_number() OVER (PARTITION BY x.name ORDER BY rank) as rnum
FROM (
SELECT a.name, a.time, a.description, 1 AS rank
FROM trac_pidgin.version a
UNION ALL
SELECT b.name, b.due as time, b.description, 2
FROM trac_pidgin.milestone b
UNION ALL
SELECT t1.version, NULL, NULL, 3
FROM trac_pidgin.ticket t1
WHERE t1.version IS NOT NULL AND t1.version != ''
UNION ALL
SELECT t1.milestone, NULL, NULL, 4
FROM trac_pidgin.ticket t1
WHERE t1.milestone IS NOT NULL AND t1.milestone != ''
) AS x
) AS y
WHERE y.rnum = 1;
`
,
)
ytVersions
:=
make
([]
youtrack
.
Version
,
len
(
versions
))
for
idx
,
version
:=
range
versions
{
ytVersions
[
idx
]
=
version
.
toYouTrack
()
}
return
ytVersions
,
err
}
func
(
v
*
version
)
toYouTrack
()
youtrack
.
Version
{
ytVersion
:=
youtrack
.
Version
{
Name
:
v
.
Name
,
Description
:
convertString
(
v
.
Description
),
}
if
v
.
Time
.
Valid
{
ytVersion
.
Released
=
true
ytVersion
.
ReleaseDate
=
convertTime
(
v
.
Time
.
Int64
)
}
return
ytVersion
}