<commit_before>package main

import (
	"fmt"
	"github.com/mdreizin/smartling/model"
	"github.com/mdreizin/smartling/service"
	"gopkg.in/urfave/cli.v1"
	"sync"
	"time"
)

var pushCommand = cli.Command{
	Name:  "push",
	Usage: "Uploads translations",
	Before: func(c *cli.Context) error {
		return invokeActions([]action{
			ensureMetadataAction,
			injectContainerAction,
			injectProjectConfigAction,
			validateProjectConfigAction,
			injectAuthTokenAction,
		}, c)
	},
	Action: func(c *cli.Context) error {
		defer elapsedTime("Push", time.Now())

		container := c.App.Metadata[containerMetadataKey].(*service.Container)
		authToken := c.App.Metadata[authTokenMetadataKey].(*model.AuthToken)
		projectConfig := c.App.Metadata[projectConfigMetadataKey].(*model.ProjectConfig)
		i := 0
		wg := &sync.WaitGroup{}

		for _, resource := range projectConfig.Resources {
			directives := resource.Directives.WithPrefix()

			for _, path := range resource.Files() {
				wg.Add(1)

				logInfo(fmt.Sprintf("Push %s...", path))

				go func(path string, resource model.ProjectResource, directives map[string]string) {
					defer wg.Done()

					stats, err := container.FileService.Push(&service.FilePushParams{
						ProjectID:  projectConfig.Project.ID,
						FileURI:    projectConfig.FileURI(path),
						FilePath:   path,
						FileType:   resource.Type,
						Authorize:  resource.AuthorizeContent,
						Directives: directives,
						AuthToken:  authToken.AccessToken,
					})

					if err == nil {
						logInfo(fmt.Sprintf("Pushed %s {Override=%t Strings=%d Words=%d}", path, stats.OverWritten, stats.StringCount, stats.WordCount))
						i++
					} else {
						logError(fmt.Sprintf("Push %s was rejected %v", path, err))
					}
				}(path, resource, directives)
			}
		}

		wg.Wait()

		logInfo(fmt.Sprintf("Pushed %d files", i))

		return nil
	},
	After: func(c *cli.Context) error {<commit_msg>fix(pushCommand): improves readability<commit_after>package main

import (
	"fmt"
	"github.com/fatih/color"
	"github.com/mdreizin/smartling/model"
	"github.com/mdreizin/smartling/service"
	"gopkg.in/urfave/cli.v1"
	"sync"
	"time"
)

var pushCommand = cli.Command{
	Name:  "push",
	Usage: "Uploads translations",
	Before: func(c *cli.Context) error {
		return invokeActions([]action{
			ensureMetadataAction,
			injectContainerAction,
			injectProjectConfigAction,
			validateProjectConfigAction,
			injectAuthTokenAction,
		}, c)
	},
	Action: func(c *cli.Context) error {
		defer elapsedTime("Push", time.Now())

		container := c.App.Metadata[containerMetadataKey].(*service.Container)
		authToken := c.App.Metadata[authTokenMetadataKey].(*model.AuthToken)
		projectConfig := c.App.Metadata[projectConfigMetadataKey].(*model.ProjectConfig)
		i := 0
		wg := &sync.WaitGroup{}

		for _, resource := range projectConfig.Resources {
			directives := resource.Directives.WithPrefix()

			for _, path := range resource.Files() {
				wg.Add(1)

				logInfo(fmt.Sprintf("Push %s...", color.MagentaString(path)))

				go func(path string, resource model.ProjectResource, directives map[string]string) {
					defer wg.Done()

					stats, err := container.FileService.Push(&service.FilePushParams{
						ProjectID:  projectConfig.Project.ID,
						FileURI:    projectConfig.FileURI(path),
						FilePath:   path,
						FileType:   resource.Type,
						Authorize:  resource.AuthorizeContent,
						Directives: directives,
						AuthToken:  authToken.AccessToken,
					})

					if err == nil {
						logInfo(fmt.Sprintf("Pushed %s {Override=%t Strings=%d Words=%d}", color.MagentaString(path), stats.OverWritten, stats.StringCount, stats.WordCount))
						i++
					} else {
						logError(fmt.Sprintf("Push %s was rejected %s", path, color.RedString(err.Error())))
					}
				}(path, resource, directives)
			}
		}

		wg.Wait()

		logInfo(fmt.Sprintf("Pushed %d files", i))

		return nil
	},
	After: func(c *cli.Context) error {
{'fraction_non_alphanumeric': 0.1385480572597137, 'fraction_numerical': 0.0015337423312883436, 'mean_word_length': 3.8189655172413794, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3993995', 'n_tokens_mistral': 1528, 'n_tokens_neox': 1253, 'n_words': 245}