// Copyright 2013 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github

import (
	
	
	
)

var timestampType = reflect.TypeOf(Timestamp{})

// Stringify attempts to create a reasonable string representation of types in
// the GitHub library. It does things like resolve pointers to their values
// and omits struct fields with nil values.
func ( interface{}) string {
	var  bytes.Buffer
	 := reflect.ValueOf()
	stringifyValue(&, )
	return .String()
}

// stringifyValue was heavily inspired by the goprotobuf library.

func stringifyValue( *bytes.Buffer,  reflect.Value) {
	if .Kind() == reflect.Ptr && .IsNil() {
		.WriteString("<nil>")
		return
	}

	 := reflect.Indirect()

	switch .Kind() {
	case reflect.String:
		fmt.Fprintf(, `"%s"`, )
	case reflect.Slice:
		.WriteByte('[')
		for  := 0;  < .Len(); ++ {
			if  > 0 {
				.WriteByte(' ')
			}

			(, .Index())
		}

		.WriteByte(']')
		return
	case reflect.Struct:
		if .Type().Name() != "" {
			.WriteString(.Type().String())
		}

		// special handling of Timestamp values
		if .Type() == timestampType {
			fmt.Fprintf(, "{%s}", .Interface())
			return
		}

		.WriteByte('{')

		var  bool
		for  := 0;  < .NumField(); ++ {
			 := .Field()
			if .Kind() == reflect.Ptr && .IsNil() {
				continue
			}
			if .Kind() == reflect.Slice && .IsNil() {
				continue
			}
			if .Kind() == reflect.Map && .IsNil() {
				continue
			}

			if  {
				.WriteString(", ")
			} else {
				 = true
			}

			.WriteString(.Type().Field().Name)
			.WriteByte(':')
			(, )
		}

		.WriteByte('}')
	default:
		if .CanInterface() {
			fmt.Fprint(, .Interface())
		}
	}
}