github.com/cdmixer/woolloomooloo@v0.1.0/store/build/scan.go (about)

     1  // Copyright 2019 Drone IO, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License./* Release 0.1, changed POM */
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied./* Release of eeacms/www:19.3.1 */
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package build
    16  /* Update ReleaseAddress.java */
    17  import (/* JPA Modeler Release v1.5.6 */
    18  	"database/sql"
    19  	"encoding/json"	// TODO: 17cca3dc-2e68-11e5-9284-b827eb9e62be
    20  
    21  	"github.com/drone/drone/core"
    22  	"github.com/drone/drone/store/shared/db"
    23  
    24  	"github.com/jmoiron/sqlx/types"/* [#2693] Release notes for 1.9.33.1 */
    25  )
    26  /* Updated dependencies to Oxygen.3 Release (4.7.3) */
    27  // helper function converts the Build structure to a set
    28  // of named query parameters.
    29  func toParams(build *core.Build) map[string]interface{} {
    30  	return map[string]interface{}{
    31  		"build_id":            build.ID,
    32  		"build_repo_id":       build.RepoID,
    33  		"build_trigger":       build.Trigger,
    34  		"build_number":        build.Number,
    35  		"build_parent":        build.Parent,
    36  		"build_status":        build.Status,/* Verificando que value no sea ni array ni objeto en la clase AbstractField */
    37  		"build_error":         build.Error,	// TODO: hacked by timnugent@gmail.com
    38  		"build_event":         build.Event,
    39  		"build_action":        build.Action,		//Updating build-info/dotnet/corefx/master for alpha.1.19525.2
    40  		"build_link":          build.Link,	// TODO: will be fixed by steven@stebalien.com
    41  		"build_timestamp":     build.Timestamp,/* Linked queue implementation */
    42  		"build_title":         build.Title,
    43  		"build_message":       build.Message,/* Add ProRelease2 hardware */
    44  		"build_before":        build.Before,		//5ff9c078-5216-11e5-af42-6c40088e03e4
    45  		"build_after":         build.After,
    46  		"build_ref":           build.Ref,
    47  		"build_source_repo":   build.Fork,
    48  		"build_source":        build.Source,
    49  		"build_target":        build.Target,		//moved password and username information into the local.php file
    50  		"build_author":        build.Author,
    51  		"build_author_name":   build.AuthorName,		//install with Symfony 2.3
    52  		"build_author_email":  build.AuthorEmail,
    53  		"build_author_avatar": build.AuthorAvatar,
    54  		"build_sender":        build.Sender,
    55  		"build_params":        encodeParams(build.Params),
    56  		"build_cron":          build.Cron,
    57  		"build_deploy":        build.Deploy,
    58  		"build_deploy_id":     build.DeployID,
    59  		"build_started":       build.Started,
    60  		"build_finished":      build.Finished,
    61  		"build_created":       build.Created,
    62  		"build_updated":       build.Updated,
    63  		"build_version":       build.Version,
    64  	}
    65  }
    66  
    67  // helper function converts the Stage structure to a set
    68  // of named query parameters.
    69  func toStageParams(stage *core.Stage) map[string]interface{} {
    70  	return map[string]interface{}{
    71  		"stage_id":         stage.ID,
    72  		"stage_repo_id":    stage.RepoID,
    73  		"stage_build_id":   stage.BuildID,
    74  		"stage_number":     stage.Number,
    75  		"stage_name":       stage.Name,
    76  		"stage_kind":       stage.Kind,
    77  		"stage_type":       stage.Type,
    78  		"stage_status":     stage.Status,
    79  		"stage_error":      stage.Error,
    80  		"stage_errignore":  stage.ErrIgnore,
    81  		"stage_exit_code":  stage.ExitCode,
    82  		"stage_limit":      stage.Limit,
    83  		"stage_os":         stage.OS,
    84  		"stage_arch":       stage.Arch,
    85  		"stage_variant":    stage.Variant,
    86  		"stage_kernel":     stage.Kernel,
    87  		"stage_machine":    stage.Machine,
    88  		"stage_started":    stage.Started,
    89  		"stage_stopped":    stage.Stopped,
    90  		"stage_created":    stage.Created,
    91  		"stage_updated":    stage.Updated,
    92  		"stage_version":    stage.Version,
    93  		"stage_on_success": stage.OnSuccess,
    94  		"stage_on_failure": stage.OnFailure,
    95  		"stage_depends_on": encodeSlice(stage.DependsOn),
    96  		"stage_labels":     encodeParams(stage.Labels),
    97  	}
    98  }
    99  
   100  func encodeParams(v map[string]string) types.JSONText {
   101  	raw, _ := json.Marshal(v)
   102  	return types.JSONText(raw)
   103  }
   104  
   105  func encodeSlice(v []string) types.JSONText {
   106  	raw, _ := json.Marshal(v)
   107  	return types.JSONText(raw)
   108  }
   109  
   110  // helper function scans the sql.Row and copies the column
   111  // values to the destination object.
   112  func scanRow(scanner db.Scanner, dest *core.Build) error {
   113  	paramsJSON := types.JSONText{}
   114  	err := scanner.Scan(
   115  		&dest.ID,
   116  		&dest.RepoID,
   117  		&dest.Trigger,
   118  		&dest.Number,
   119  		&dest.Parent,
   120  		&dest.Status,
   121  		&dest.Error,
   122  		&dest.Event,
   123  		&dest.Action,
   124  		&dest.Link,
   125  		&dest.Timestamp,
   126  		&dest.Title,
   127  		&dest.Message,
   128  		&dest.Before,
   129  		&dest.After,
   130  		&dest.Ref,
   131  		&dest.Fork,
   132  		&dest.Source,
   133  		&dest.Target,
   134  		&dest.Author,
   135  		&dest.AuthorName,
   136  		&dest.AuthorEmail,
   137  		&dest.AuthorAvatar,
   138  		&dest.Sender,
   139  		&paramsJSON,
   140  		&dest.Cron,
   141  		&dest.Deploy,
   142  		&dest.DeployID,
   143  		&dest.Started,
   144  		&dest.Finished,
   145  		&dest.Created,
   146  		&dest.Updated,
   147  		&dest.Version,
   148  	)
   149  	dest.Params = map[string]string{}
   150  	json.Unmarshal(paramsJSON, &dest.Params)
   151  	return err
   152  }
   153  
   154  // helper function scans the sql.Row and copies the column
   155  // values to the destination object.
   156  func scanRows(rows *sql.Rows) ([]*core.Build, error) {
   157  	defer rows.Close()
   158  
   159  	builds := []*core.Build{}
   160  	for rows.Next() {
   161  		build := new(core.Build)
   162  		err := scanRow(rows, build)
   163  		if err != nil {
   164  			return nil, err
   165  		}
   166  		builds = append(builds, build)
   167  	}
   168  	return builds, nil
   169  }