func newDraftRepositoryRelease(id int, version string) github.RepositoryRelease {
	return github.RepositoryRelease{
		TagName: github.String(version),
		Draft:   github.Bool(true),
		ID:      github.Int(id),
	}
}
func (c *OutCommand) Run(sourceDir string, request OutRequest) (OutResponse, error) {
	params := request.Params

	name, err := c.fileContents(filepath.Join(sourceDir, request.Params.NamePath))
	if err != nil {
		return OutResponse{}, err
	}

	tag, err := c.fileContents(filepath.Join(sourceDir, request.Params.TagPath))
	if err != nil {
		return OutResponse{}, err
	}

	body := ""
	if request.Params.BodyPath != "" {
		body, err = c.fileContents(filepath.Join(sourceDir, request.Params.BodyPath))
		if err != nil {
			return OutResponse{}, err
		}
	}

	targetCommitish := ""
	if request.Params.CommitishPath != "" {
		targetCommitish, err = c.fileContents(filepath.Join(sourceDir, request.Params.CommitishPath))
		if err != nil {
			return OutResponse{}, err
		}
	}

	draft := request.Params.Draft

	release := &github.RepositoryRelease{
		Name:            github.String(name),
		TagName:         github.String(tag),
		Body:            github.String(body),
		Draft:           github.Bool(draft),
		TargetCommitish: github.String(targetCommitish),
	}

	existingReleases, err := c.github.ListReleases()
	if err != nil {
		return OutResponse{}, err
	}

	var existingRelease *github.RepositoryRelease
	for _, e := range existingReleases {
		if e.TagName != nil && *e.TagName == tag {
			existingRelease = &e
			break
		}
	}

	if existingRelease != nil {
		existingRelease.Name = github.String(name)
		existingRelease.Body = github.String(body)
		existingRelease.TargetCommitish = github.String(targetCommitish)

		for _, asset := range existingRelease.Assets {
			fmt.Fprintf(c.writer, "clearing existing asset: %s\n", *asset.Name)

			err := c.github.DeleteReleaseAsset(asset)
			if err != nil {
				return OutResponse{}, err
			}
		}

		fmt.Fprintf(c.writer, "updating release %s\n", name)

		release, err = c.github.UpdateRelease(*existingRelease)
	} else {
		fmt.Fprintf(c.writer, "creating release %s\n", name)
		release, err = c.github.CreateRelease(*release)
	}

	if err != nil {
		return OutResponse{}, err
	}

	for _, fileGlob := range params.Globs {
		matches, err := filepath.Glob(filepath.Join(sourceDir, fileGlob))
		if err != nil {
			return OutResponse{}, err
		}

		if len(matches) == 0 {
			return OutResponse{}, fmt.Errorf("could not find file that matches glob '%s'", fileGlob)
		}

		for _, filePath := range matches {
			file, err := os.Open(filePath)
			if err != nil {
				return OutResponse{}, err
			}

			fmt.Fprintf(c.writer, "uploading %s\n", filePath)

			name := filepath.Base(filePath)
			err = c.github.UploadReleaseAsset(*release, name, file)
			if err != nil {
				return OutResponse{}, err
			}

			file.Close()
		}
	}

	return OutResponse{
		Version:  versionFromDraft(release),
		Metadata: metadataFromRelease(release),
	}, nil
}
func newDraftWithNilTagRepositoryRelease(id int) github.RepositoryRelease {
	return github.RepositoryRelease{
		Draft: github.Bool(true),
		ID:    github.Int(id),
	}
}
		existingAssets := []github.ReleaseAsset{
			{
				ID:   github.Int(456789),
				Name: github.String("unicorns.txt"),
			},
			{
				ID:   github.Int(3450798),
				Name: github.String("rainbows.txt"),
			},
		}

		BeforeEach(func() {
			githubClient.ListReleasesReturns([]github.RepositoryRelease{
				{
					ID:    github.Int(1),
					Draft: github.Bool(true),
				},
				{
					ID:      github.Int(112),
					TagName: github.String("some-tag-name"),
					Assets:  existingAssets,
					Draft:   github.Bool(false),
				},
			}, nil)

			namePath := filepath.Join(sourcesDir, "name")
			bodyPath := filepath.Join(sourcesDir, "body")
			tagPath := filepath.Join(sourcesDir, "tag")

			file(namePath, "v0.3.12")
			file(bodyPath, "this is a great release")