<commit_before>###
Copyright 2016-2017 Resin.io

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
###

dockerUtils = require('../utils/docker')

LATEST = 'latest'

getApplicationsWithSuccessfulBuilds = (deviceType) ->
	preload = require('resin-preload')
	resin = require('resin-sdk').fromSharedOptions()

	resin.pine.get
		resource: 'my_application'
		options:
			filter:
				device_type: deviceType
				owns__release:
					$any:
						$alias: 'r'
						$expr:
							r:
								status: 'success'
			expand: preload.applicationExpandOptions
			select: [ 'id', 'app_name', 'device_type', 'commit', 'should_track_latest_release' ]
			orderby: 'app_name asc'

selectApplication = (deviceType) ->
	visuals = require('resin-cli-visuals')
	form = require('resin-cli-form')
	{ expectedError } = require('../utils/patterns')

	applicationInfoSpinner = new visuals.Spinner('Downloading list of applications and releases.')
	applicationInfoSpinner.start()

	getApplicationsWithSuccessfulBuilds(deviceType)
	.then (applications) ->
		applicationInfoSpinner.stop()
		if applications.length == 0
			expectedError("You have no apps with successful releases for a '#{deviceType}' device type.")
		form.ask
			message: 'Select an application'
			type: 'list'
			choices: applications.map (app) ->
				name: app.app_name
				value: app

selectApplicationCommit = (releases) ->
	form = require('resin-cli-form')
	{ expectedError } = require('../utils/patterns')

	if releases.length == 0
		expectedError('This application has no successful releases.')
	DEFAULT_CHOICE = { 'name': LATEST, 'value': LATEST }
	choices = [ DEFAULT_CHOICE ].concat releases.map (release) -><commit_msg>Prefix all pine options with '$' in preload to avoid pine warnings.<commit_after>###
Copyright 2016-2017 Resin.io

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
###

dockerUtils = require('../utils/docker')

LATEST = 'latest'

getApplicationsWithSuccessfulBuilds = (deviceType) ->
	preload = require('resin-preload')
	resin = require('resin-sdk').fromSharedOptions()

	resin.pine.get
		resource: 'my_application'
		options:
			$filter:
				device_type: deviceType
				owns__release:
					$any:
						$alias: 'r'
						$expr:
							r:
								status: 'success'
			$expand: preload.applicationExpandOptions
			$select: [ 'id', 'app_name', 'device_type', 'commit', 'should_track_latest_release' ]
			$orderby: 'app_name asc'

selectApplication = (deviceType) ->
	visuals = require('resin-cli-visuals')
	form = require('resin-cli-form')
	{ expectedError } = require('../utils/patterns')

	applicationInfoSpinner = new visuals.Spinner('Downloading list of applications and releases.')
	applicationInfoSpinner.start()

	getApplicationsWithSuccessfulBuilds(deviceType)
	.then (applications) ->
		applicationInfoSpinner.stop()
		if applications.length == 0
			expectedError("You have no apps with successful releases for a '#{deviceType}' device type.")
		form.ask
			message: 'Select an application'
			type: 'list'
			choices: applications.map (app) ->
				name: app.app_name
				value: app

selectApplicationCommit = (releases) ->
	form = require('resin-cli-form')
	{ expectedError } = require('../utils/patterns')

	if releases.length == 0
		expectedError('This application has no successful releases.')
	DEFAULT_CHOICE = { 'name': LATEST, 'value': LATEST }
	choices = [ DEFAULT_CHOICE ].concat releases.map (release) ->
{'fraction_non_alphanumeric': 0.11224018475750577, 'fraction_numerical': 0.006466512702078522, 'mean_word_length': 4.366790582403965, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2070113', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1261, 'n_words': 396}