* Fixing CI telemetry prompting

* Adding lock file changes

* Fixing tests to detect CI

* Modifying logic to favor existing config file

* Removing condition on function
This commit is contained in:
Emilio Munoz 2020-02-11 10:50:07 -08:00 коммит произвёл GitHub
Родитель a58fa27622
Коммит fe3b112de8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 53 добавлений и 16 удалений

Просмотреть файл

@ -48,6 +48,7 @@ dependencies:
glob: 7.1.6
https-proxy-agent: 2.2.4
intercept-stdout: 0.1.2
is-ci: 2.0.0
json-schema-merge-allof: 0.6.0
json-schema-ref-parser: 7.1.3
latest-version: 4.0.0
@ -1279,6 +1280,10 @@ packages:
dev: false
resolution:
integrity: sha512-i70fVHhmV3DtTl6nqvZOnIjbY0Pe4kAUjwHj8z0zAdgBtYrJyYwLKCCuRBQ5ppkyL0AkN7HKRnETdmdp1zqNXw==
/ci-info/2.0.0:
dev: false
resolution:
integrity: sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==
/class-utils/0.3.6:
dependencies:
arr-union: 3.1.0
@ -3060,6 +3065,13 @@ packages:
node: '>= 0.4'
resolution:
integrity: sha512-ESKv5sMCJB2jnHTWZ3O5itG+O128Hsus4K4Qh1h2/cgn2vbgnLSVqfV46AeJA9D5EeeLa9w81KUXMtn34zhX+Q==
/is-ci/2.0.0:
dependencies:
ci-info: 2.0.0
dev: false
hasBin: true
resolution:
integrity: sha512-YfJT7rkpQB0updsdHLGWrvhBJfcfzNNawYDNIyQXJz0IViGf75O8EBPKSdvw2rF+LGCsX4FZ8tcr3b19LcZq4w==
/is-data-descriptor/0.1.4:
dependencies:
kind-of: 3.2.2
@ -6045,7 +6057,7 @@ packages:
dev: false
name: '@rush-temp/bf-chatdown'
resolution:
integrity: sha512-u9dwkEjLX2IEAsUCwN40KLqZzDTiQolaPKb+dXzAibc303zGEP8h0MNZpHvT9e9/wDhzTQzSuvC8ZbWkWoBtyQ==
integrity: sha512-Kpnd+g8xRbeN6t1LtDIwTjWdzLQ3WxnQQQkAHZGM+eK4BlTJrTNTnz3RW0owqM0Leao0y+IvP+iuFQyNYQKstA==
tarball: 'file:projects/bf-chatdown.tgz'
version: 0.0.0
'file:projects/bf-cli-command.tgz':
@ -6085,7 +6097,7 @@ packages:
dev: false
name: '@rush-temp/bf-cli-command'
resolution:
integrity: sha512-Cx2jECsJgRe4K74pqmjEoddPmrayTDmMg/rD90kRYiQ6agSNWbC7o638KTUDYZ5VJlhu+PEV/MuVG0oV+wu19Q==
integrity: sha512-Ka3DtQMqMdVH/dW1MvF7sWulMlkvIXapd9Emm577bVthPp6N6fEJigkLJCRGWI0D4RXG4ldHrnhePmsW9fwesg==
tarball: 'file:projects/bf-cli-command.tgz'
version: 0.0.0
'file:projects/bf-cli-config.tgz':
@ -6114,7 +6126,7 @@ packages:
dev: false
name: '@rush-temp/bf-cli-config'
resolution:
integrity: sha512-ZvUZsW96vljeLO69GRz/kfBazChVv9O6BkikOIQCHUbUP32PzIh8a0jjEmppA+/RtqajtmKQWGq0q5DEQY4x5A==
integrity: sha512-vwZf1fXZ7BWQsJjKHFMEQ95zRfQ48Na7ae9cMH36cw/fk/a6MYUkzwSgSabel0S2D8uT/BodVucYXJXPfl9NTw==
tarball: 'file:projects/bf-cli-config.tgz'
version: 0.0.0
'file:projects/bf-cli-plugins.tgz':
@ -6143,7 +6155,7 @@ packages:
dev: false
name: '@rush-temp/bf-cli-plugins'
resolution:
integrity: sha512-2n8WG0y6vxBpyUrSJLVWwLcwUN+FqR8wI5htyMvDmPJOBp/PnH4WrupuQXDhl0UacI6LBhI4RWiZtunIkJ1zBw==
integrity: sha512-fegDj5NfXQCsabktk5fStFptRwmJccyH0qzjDqasi0mhTjLi72+ucovjYrzbVmrA73LdOoIsRIAT8tuCfLkkMg==
tarball: 'file:projects/bf-cli-plugins.tgz'
version: 0.0.0
'file:projects/bf-dialog.tgz':
@ -6188,7 +6200,7 @@ packages:
dev: false
name: '@rush-temp/bf-dialog'
resolution:
integrity: sha512-wLqkv6TapzOAmIExo+h14rfw7e2BinNmi30yDcV+01KndJSTH41dyhmdpD0jnvru7YMYRNaQoh8zpea6Y2/6dg==
integrity: sha512-s/80P9QduIAYy3HGOycjq+smgFPZD8bANxSojRNm1k+IjEXD8DYhZb5b03EGajcNTvIxgWIDqyefgwcvn1hZPA==
tarball: 'file:projects/bf-dialog.tgz'
version: 0.0.0
'file:projects/bf-dispatcher.tgz':
@ -6217,7 +6229,7 @@ packages:
dev: false
name: '@rush-temp/bf-dispatcher'
resolution:
integrity: sha512-s4Ar6m12VKpS8u3yyNtXMaShnRZTOCUIFYwXTyXXmN4oX8mkbG0O4zLB47xP68mDHgAvtQ8BNVg42vzq/or0wg==
integrity: sha512-eXMc0AkAcBYSAjDKfUoHVjF+huBN7ESR1I9do3Pi4BAhz/5DrIz2u7Uy4iHGWkZoBEu/izsfz1UgEKnhn+pUbw==
tarball: 'file:projects/bf-dispatcher.tgz'
version: 0.0.0
'file:projects/bf-lu.tgz':
@ -6260,7 +6272,7 @@ packages:
dev: false
name: '@rush-temp/bf-lu'
resolution:
integrity: sha512-Hs49Cqyc/xZQ3Buw+cg53NLAAEw42pSuaq2hFGIWjtwiZcmmLOAyIxSkBXFsq/zKinDSx4k50xovkZTYH1TtTQ==
integrity: sha512-g5LXnFL9CB6a/KTzOv3maI9SP0mYK42CE+f9z3ozycf7sQzXsg+pkS9sx3UxcbX7/TspDTly+KQbNSELmx5HGA==
tarball: 'file:projects/bf-lu.tgz'
version: 0.0.0
'file:projects/bf-luis-cli.tgz':
@ -6299,7 +6311,7 @@ packages:
dev: false
name: '@rush-temp/bf-luis-cli'
resolution:
integrity: sha512-JH3A+XDHWIh3PXmu/g7kh1Fe5m/3IsBfTaL6Ofq63DbQfjaMJxX6f63Ut4mDR/2uvb/zF2X/m8kHQtsZuwyg2g==
integrity: sha512-LIoHcGU2SGVD5OhHi4LcfIDgbN4KaqpnMoc20vLCN7uNwne+mNxPpJOrVs4zGTeAKgs9X7ynMiG5MZ7Gc5YoCw==
tarball: 'file:projects/bf-luis-cli.tgz'
version: 0.0.0
'file:projects/bf-qnamaker.tgz':
@ -6307,6 +6319,7 @@ packages:
'@oclif/command': 1.5.19
'@oclif/config': 1.13.3
'@oclif/dev-cli': 1.22.2
'@oclif/errors': 1.2.2
'@oclif/parser': 3.8.4
'@oclif/plugin-help': 2.2.3
'@oclif/test': 1.2.5
@ -6347,7 +6360,7 @@ packages:
dev: false
name: '@rush-temp/bf-qnamaker'
resolution:
integrity: sha512-XipAjyrWFoenzFZyJlddBKLWL5RwCtS2/SuOi3DBun68j+LPXQ4MlOjlTPpu+dZLNjQXDXiq/UAV97vhhLTu9Q==
integrity: sha512-ZOEixDpV+YpN0gLsfmqjG77rrZILkowKeY0oZsxVnWcEjeuAobJ7dH+fvWaF5pb6pNE60Av7AOsabaU0IUKNFA==
tarball: 'file:projects/bf-qnamaker.tgz'
version: 0.0.0
'file:projects/botframework-cli.tgz':
@ -6368,6 +6381,7 @@ packages:
cli-ux: 5.4.1
fs-extra: 7.0.1
globby: 8.0.2
is-ci: 2.0.0
latest-version: 4.0.0
mocha: 6.2.2
nyc: 14.1.1
@ -6380,7 +6394,7 @@ packages:
dev: false
name: '@rush-temp/botframework-cli'
resolution:
integrity: sha512-7fTuB7y3q0jzPX309m4bsspkMmhYh3quYuUA+9KdadGlxrwiHBy09tV9SKr2pwCy2j0TIGZJTm932W9+MDgzCg==
integrity: sha512-Geg+CNIaX/KctYUyAj5900dab9VIyvrOblmxdRQWbGqyMqtItl8rtSknvld36Fdr1DCYnBk+WlCAWU1n54ee1w==
tarball: 'file:projects/botframework-cli.tgz'
version: 0.0.0
registry: ''
@ -6434,6 +6448,7 @@ specifiers:
glob: ^7.1.3
https-proxy-agent: ^2.2.1
intercept-stdout: ^0.1.2
is-ci: 2.0.0
json-schema-merge-allof: ^0.6.0
json-schema-ref-parser: ^7.1.0
latest-version: ^4.0.0

Просмотреть файл

@ -70,6 +70,7 @@
"chalk": "2.4.1",
"cli-ux": "^5.3.0",
"fs-extra": "^7.0.1",
"is-ci":"2.0.0",
"latest-version": "^4.0.0",
"semver": "^5.5.1",
"tslib": "^1.9.3"

Просмотреть файл

@ -3,6 +3,7 @@ const {cli} = require('cli-ux')
const chalk = require('chalk')
const path = require('path')
const fs = require('fs-extra')
const isCI = require('is-ci')
const pjson = require('../package.json');
const windowsHomedriveHome = () => process.env.HOMEDRIVE && process.env.HOMEPATH && path.join(process.env.HOMEDRIVE, process.env.HOMEPATH)
@ -37,7 +38,10 @@ const getUserConfig = async () => {
try {
const userConfig = await getUserConfig()
userConfig.lastVersionCheck = new Date()
if (userConfig.telemetry === null) {
if (!process.env.BF_CLI_TELEMETRY &&
!isCI &&
userConfig.telemetry === null) {
const disableTelemetry = await cli.prompt(chalk.red('Help us improve products by allowing Microsoft to collect anonymous command and flags usage: (Y/N)'))
if (disableTelemetry === 'Y' || disableTelemetry === 'y') {
userConfig.telemetry = true

Просмотреть файл

@ -10,6 +10,7 @@ const chalk = require('chalk')
const path = require('path')
const latestVersion = require('latest-version')
const semver = require('semver')
const isCI = require('is-ci')
const hook: Hook<'init'> = async function (opts) {
// get config settings
@ -70,7 +71,9 @@ const hook: Hook<'init'> = async function (opts) {
// Ensure telemetry is set
try {
if (userConfig.telemetry === null) {
if (process.env.BF_CLI_TELEMETRY) {
userConfig.telemetry = process.env.BF_CLI_TELEMETRY.toLowerCase() === 'true' ? true : false
} else if (userConfig.telemetry === null && !isCI) {
const disableTelemetry = await cli.prompt(chalk.red('Help us improve products by allowing Microsoft to collect anonymous command and flags usage: (Y/N)'))
if (disableTelemetry === 'Y' || disableTelemetry === 'y') {
userConfig.telemetry = true
@ -89,7 +92,7 @@ const hook: Hook<'init'> = async function (opts) {
await writeUserConfig(userConfig)
}
this.config.pjson.telemetry = userConfig.telemetry
this.config.pjson.telemetry = userConfig.telemetry === null ? false : userConfig.telemetry
/* tslint:disable:no-unused */
} catch (err) {

Просмотреть файл

@ -4,6 +4,7 @@ import * as fs from 'fs-extra'
const path = require('path')
const semver = require('semver')
const os = require('os')
const isCI = require('is-ci')
const lastversioncheck = path.join(__dirname, '../fixtures/lastversioncheck')
const upgradeavailable = path.join(__dirname, '../fixtures/upgradeavailable')
@ -46,7 +47,11 @@ describe('Check if telemetry is set if config is null', () => {
.stdout()
.hook('init', {argv: ['arg']}, {root: rootTelemetryNull})
.do(output => {
expect(output.stdout).to.contain('Telemetry will remain disabled')
if (!isCI) {
expect(output.stdout).to.contain('Telemetry will remain disabled')
} else {
expect(output.stdout).to.be.empty
}
})
.it('it should disable telemetry when a user opts out')
@ -56,7 +61,11 @@ describe('Check if telemetry is set if config is null', () => {
.stdout()
.hook('init', {argv: ['arg']}, {root: rootTelemetryNull})
.do(output => {
expect(output.stdout).to.contain('Telemetry has been enabled')
if (!isCI) {
expect(output.stdout).to.contain('Telemetry has been enabled')
} else {
expect(output.stdout).to.be.empty
}
})
.it('it should enable telemetry when a user opts in')
})
@ -132,19 +141,24 @@ describe('Update available to stdout', () => {
})
describe('bypass version update if it\'s already been checked today', async () => {
let originalDate
beforeEach(async () => {
// runs before all tests in this block
const today = new Date()
let userConfig = await fs.readJSON(path.join(lastversioncheck, 'package.json'))
originalDate = userConfig.lastversioncheck
userConfig.lastversioncheck = today
fs.writeFileSync(path.join(lastversioncheck, 'package.json'), JSON.stringify(userConfig, null, 2))
fs.mkdirSync(pathToConfigJsonUpdate)
fs.writeFileSync(path.join(pathToConfigJsonUpdate, 'config.json'), JSON.stringify({telemetry: true}, null, 2))
});
afterEach(function() {
afterEach(async function() {
// runs after all tests in this block
fs.removeSync(pathToConfigJsonUpdate)
let userConfig = await fs.readJSON(path.join(lastversioncheck, 'package.json'))
userConfig.lastversioncheck = originalDate
fs.writeFileSync(path.join(lastversioncheck, 'package.json'), JSON.stringify(userConfig, null, 2))
});
test