grim/youtrack-import

0ce6488c1f5f
Parents d70c81dc02fc
Children 33ea22a7724f
Fix up the version and subsystem code to handle additional fields
--- a/bitbucket/converter.go Fri Jul 03 22:56:34 2020 -0500
+++ b/bitbucket/converter.go Tue Jul 07 23:42:04 2020 -0500
@@ -204,15 +204,15 @@
}
// create a string slice of all the components
- components := make([]string, len(a.Components))
+ components := make([]youtrack.OwnedField, len(a.Components))
for i := 0; i < len(a.Components); i++ {
- components[i] = a.Components[i].Name
+ components[i] = youtrack.OwnedField{Value: a.Components[i].Name}
}
// create a string slice of all the versions
- versions := make([]string, len(a.Versions))
+ versions := make([]youtrack.Version, len(a.Versions))
for i := 0; i < len(a.Versions); i++ {
- versions[i] = a.Versions[i].Name
+ versions[i] = youtrack.Version{Name: a.Versions[i].Name}
}
// convert all of the issues
--- a/build-and-run Fri Jul 03 22:56:34 2020 -0500
+++ b/build-and-run Tue Jul 07 23:42:04 2020 -0500
@@ -4,5 +4,5 @@
echo -n "deleting project \"${1}\" ... "
curl -X DELETE -H "Authorization: Bearer ${YOUTRACK_TOKEN}" "${YOUTRACK_URL}rest/admin/project/${1}"
echo "done."
-./youtrack-import --project-id="${1}" --project-name="${2}" bitbucket "${3}" "${4}" "${5}"
+./youtrack-import --project-id="${1}" --project-name="${2}" trac "${3}" "--import-users=${4}"
--- a/trac/components.go Fri Jul 03 22:56:34 2020 -0500
+++ b/trac/components.go Tue Jul 07 23:42:04 2020 -0500
@@ -1,13 +1,38 @@
package trac
-import ()
+import (
+ "database/sql"
+
+ "keep.imfreedom.org/grim/youtrack-import/youtrack"
+)
-func (e *environment) loadComponents() ([]string, error) {
- components := []string{}
+type component struct {
+ Name string `db:"name"`
+ Owner sql.NullString `db:"owner"`
+ Description sql.NullString `db:"description"`
+}
+
+func (e *environment) loadComponents() ([]component, error) {
+ components := []component{}
err := e.db.Select(
&components,
- "SELECT distinct(component) from ticket ORDER BY component ASC",
+ `SELECT
+ distinct(t.component) AS name,
+ c.owner AS owner,
+ c.description AS description
+ FROM component c
+ FULL JOIN trac_pidgin.ticket t ON
+ c.name = t.component
+ ORDER BY t.component`,
)
return components, err
}
+
+func (c *component) toYouTrack() youtrack.OwnedField {
+ return youtrack.OwnedField{
+ Value: c.Name,
+ Description: convertString(c.Description),
+ Owner: convertString(c.Owner),
+ }
+}
--- a/trac/project.go Fri Jul 03 22:56:34 2020 -0500
+++ b/trac/project.go Tue Jul 07 23:42:04 2020 -0500
@@ -14,10 +14,23 @@
fmt.Printf("loaded %d users\n", len(users))
+ versions, err := e.loadVersions()
+ if err != nil {
+ return nil, err
+ }
+ ytVersions := make([]youtrack.Version, len(versions))
+ for idx, version := range versions {
+ ytVersions[idx] = version.toYouTrack()
+ }
+
components, err := e.loadComponents()
if err != nil {
return nil, err
}
+ ytSubsystems := make([]youtrack.OwnedField, len(components))
+ for idx, component := range components {
+ ytSubsystems[idx] = component.toYouTrack()
+ }
tracTickets, err := e.loadTickets()
if err != nil {
@@ -44,7 +57,8 @@
project := &youtrack.Project{
Issues: issues,
Users: sliceUsers,
- Subsystems: components,
+ Versions: ytVersions,
+ Subsystems: ytSubsystems,
}
fmt.Printf("Project: has %d issues\n", len(issues))
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/trac/versions.go Tue Jul 07 23:42:04 2020 -0500
@@ -0,0 +1,37 @@
+package trac
+
+import (
+ "database/sql"
+
+ "keep.imfreedom.org/grim/youtrack-import/youtrack"
+)
+
+type version struct {
+ Name string `db:"name"`
+ Time int64 `db:"time"`
+ Description sql.NullString `db:"description"`
+}
+
+func (e *environment) loadVersions() ([]version, error) {
+ versions := []version{}
+ err := e.db.Select(
+ &versions,
+ "SELECT * from version ORDER BY name DESC",
+ )
+
+ return versions, err
+}
+
+func (v *version) toYouTrack() youtrack.Version {
+ ytVersion := youtrack.Version{
+ Name: v.Name,
+ Description: convertString(v.Description),
+ }
+
+ if v.Time != 0 {
+ ytVersion.Released = true
+ ytVersion.ReleaseDate = convertTime(v.Time)
+ }
+
+ return ytVersion
+}
--- a/youtrack/import.go Fri Jul 03 22:56:34 2020 -0500
+++ b/youtrack/import.go Tue Jul 07 23:42:04 2020 -0500
@@ -31,6 +31,11 @@
}
fmt.Printf("done.\n")
+ // create the users
+ if err := client.ImportUsers(p); err != nil {
+ return err
+ }
+
// create the subsystems
if err := client.CreateSubsystems(p); err != nil {
return err
@@ -41,11 +46,6 @@
return err
}
- // create the users
- if err := client.ImportUsers(p); err != nil {
- return err
- }
-
// create the issues
if err := client.ImportIssues(p); err != nil {
return err
--- a/youtrack/ownedfield.go Fri Jul 03 22:56:34 2020 -0500
+++ b/youtrack/ownedfield.go Tue Jul 07 23:42:04 2020 -0500
@@ -4,6 +4,7 @@
"encoding/xml"
"fmt"
"net/http"
+ "net/url"
)
type OwnedField struct {
@@ -39,10 +40,20 @@
return bundle, xml.NewDecoder(resp.Body).Decode(bundle)
}
-func (c *Client) AppendOwnedFieldBundle(name, value string) error {
+func (c *Client) AppendOwnedFieldBundle(name string, field OwnedField) error {
+ baseUri := c.uri + "/admin/customfield/ownedFieldBundle/" + name + "/" + field.Value
+
+ values := url.Values{}
+ if field.Description != "" {
+ values.Add("description", field.Description)
+ }
+ if field.Owner != "" {
+ values.Add("login", field.Owner)
+ }
+
resp, err := c.request(
http.MethodPut,
- c.uri+"/admin/customfield/ownedFieldBundle/"+name+"/"+value,
+ baseUri+"?"+values.Encode(),
nil,
)
if err != nil {
@@ -52,7 +63,7 @@
defer resp.Body.Close()
if err := c.checkStatus(resp, http.StatusCreated); err != nil {
- return fmt.Errorf("failed to append %q to %q: %s", value, name, err)
+ return fmt.Errorf("failed to append %q to %q: %s", field.Value, name, err)
}
return nil
--- a/youtrack/project.go Fri Jul 03 22:56:34 2020 -0500
+++ b/youtrack/project.go Tue Jul 07 23:42:04 2020 -0500
@@ -11,8 +11,8 @@
Users []*User
- Subsystems []string
- Versions []string
+ Subsystems []OwnedField
+ Versions []Version
Issues []*Issue
}
--- a/youtrack/subsystems.go Fri Jul 03 22:56:34 2020 -0500
+++ b/youtrack/subsystems.go Tue Jul 07 23:42:04 2020 -0500
@@ -32,9 +32,9 @@
// now run through the map and add the new values
for _, subsystem := range p.Subsystems {
- fmt.Printf("creating subsystem %q ... ", subsystem)
+ fmt.Printf("creating subsystem %q ... ", subsystem.Value)
- if _, found := existing[subsystem]; found {
+ if _, found := existing[subsystem.Value]; found {
fmt.Printf("already exists.\n")
continue
}
--- a/youtrack/version.go Fri Jul 03 22:56:34 2020 -0500
+++ b/youtrack/version.go Tue Jul 07 23:42:04 2020 -0500
@@ -4,8 +4,20 @@
"encoding/xml"
"fmt"
"net/http"
+ "net/url"
+ "time"
)
+type Version struct {
+ Name string
+ Description string
+
+ Released bool
+ ReleaseDate time.Time
+
+ Archived bool
+}
+
type VersionField struct {
Released bool `xml:"released,attr"`
Archived bool `xml:"archived,attr"`
@@ -55,10 +67,27 @@
return bundle, xml.NewDecoder(resp.Body).Decode(bundle)
}
-func (c *Client) AppendVersionFieldBundle(name, value string) error {
+func (c *Client) AppendVersionFieldBundle(name string, version Version) error {
+ baseUri := c.uri + "/admin/customfield/versionBundle/" + name + "/" + version.Name
+
+ values := url.Values{}
+
+ if version.Description != "" {
+ values.Add("description", version.Description)
+ }
+ if version.Released != false {
+ values.Add("released", "true")
+ }
+ if !version.ReleaseDate.IsZero() {
+ values.Add("releaseDate", fmt.Sprintf("%d", version.ReleaseDate.Unix()*1000))
+ }
+ if version.Archived != false {
+ values.Add("archived", "true")
+ }
+
resp, err := c.request(
http.MethodPut,
- c.uri+"/admin/customfield/versionBundle/"+name+"/"+value,
+ baseUri+"?"+values.Encode(),
nil,
)
if err != nil {
@@ -68,7 +97,7 @@
defer resp.Body.Close()
if err := c.checkStatus(resp, http.StatusCreated); err != nil {
- return fmt.Errorf("failed to append %q to %q: %v", value, name, err)
+ return fmt.Errorf("failed to append %q to %q: %v", version.Name, name, err)
}
return nil
@@ -88,9 +117,9 @@
// now run through the version slice and add all the versions
for _, version := range p.Versions {
- fmt.Printf("creating version %q ... ", version)
+ fmt.Printf("creating version %q ... ", version.Name)
- if _, found := existing[version]; found {
+ if _, found := existing[version.Name]; found {
fmt.Printf("already exists.\n")
continue
}