Skip to content

Commit

Permalink
Enforce using async-await [f-droid] (#2241)
Browse files Browse the repository at this point in the history
Close #2028
  • Loading branch information
paulmelnikow authored Nov 4, 2018
1 parent 72768d3 commit d55e1c1
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 19 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ rules:
no-extension-in-require/main: "error"
object-shorthand: ["error", "properties"]
prefer-template: "error"
promise/prefer-await-to-then: "error"

# Mocha-related.
mocha/no-exclusive-tests: "error"
Expand Down
1 change: 1 addition & 0 deletions dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ if (capitals.created || underscores.created) {
const allFiles = danger.git.created_files.concat(danger.git.modified_files)

allFiles.forEach(file => {
// eslint-disable-next-line promise/prefer-await-to-then
danger.git.diffForFile(file).then(diff => {
if (/\+.*assert[(.]/.test(diff.diff)) {
warn(
Expand Down
2 changes: 2 additions & 0 deletions lib/result-sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ function sendSVG(res, askres, end) {
function sendOther(format, res, askres, end) {
askres.setHeader('Content-Type', `image/${format}`)
svg2img(res, format)
// This interacts with callback code and can't use async/await.
// eslint-disable-next-line promise/prefer-await-to-then
.then(data => {
end(null, { template: streamFromString(data) })
})
Expand Down
2 changes: 2 additions & 0 deletions lib/suggest.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ function setRoutes(allowedOrigin, githubApiProvider, server) {
}

findSuggestions(githubApiProvider, url)
// This interacts with callback code and can't use async/await.
// eslint-disable-next-line promise/prefer-await-to-then
.then(badges => {
end({ badges })
})
Expand Down
2 changes: 2 additions & 0 deletions services/chrome-web-store/chrome-web-store.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ module.exports = class ChromeWebStore extends LegacyService {
}
chromeWebStore
.convert(buffer)
// Switch to async/await when this is refactored.
// eslint-disable-next-line promise/prefer-await-to-then
.then(value => {
let rating
switch (type) {
Expand Down
37 changes: 18 additions & 19 deletions services/f-droid/f-droid.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,30 @@ module.exports = class FDroid extends BaseService {
async fetch({ appId }) {
// currently, we only use the txt format. There are few apps using the yml format.
const url = `https://gitlab.com/fdroid/fdroiddata/raw/master/metadata/${appId}.txt`
return this._request({
const { buffer } = await this._request({
url,
options: {},
errorMessages: {
404: 'app not found',
},
}).then(({ res, buffer }) => {
const metadata = buffer.toString()
// we assume the layout as provided here:
// https://gitlab.com/fdroid/fdroiddata/raw/master/metadata/axp.tool.apkextractor.txt
const positionOfCurrentVersionAtEndOfTheFile = metadata.lastIndexOf(
'Current Version:'
) // credits: https://stackoverflow.com/a/11134049
const lastVersion = metadata.substring(
positionOfCurrentVersionAtEndOfTheFile
)
const match = lastVersion.match(/^Current Version:\s*(.*?)\s*$/m)
if (!match) {
throw new InvalidResponse({
prettyMessage: 'invalid response',
underlyingError: new Error('could not find version on website'),
})
}
return { version: match[1] }
})
const metadata = buffer.toString()
// we assume the layout as provided here:
// https://gitlab.com/fdroid/fdroiddata/raw/master/metadata/axp.tool.apkextractor.txt
const positionOfCurrentVersionAtEndOfTheFile = metadata.lastIndexOf(
'Current Version:'
) // credits: https://stackoverflow.com/a/11134049
const lastVersion = metadata.substring(
positionOfCurrentVersionAtEndOfTheFile
)
const match = lastVersion.match(/^Current Version:\s*(.*?)\s*$/m)
if (!match) {
throw new InvalidResponse({
prettyMessage: 'invalid response',
underlyingError: new Error('could not find version on website'),
})
}
return { version: match[1] }
}

static render({ version }) {
Expand Down
2 changes: 2 additions & 0 deletions services/php-eye/php-eye-php-version.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ module.exports = class PhpEyePhpVersion extends LegacyService {
}
const badgeData = getBadgeData('php tested', data)
getPhpReleases(githubApiProvider)
// Switch to async/await when this is refactored.
// eslint-disable-next-line promise/prefer-await-to-then
.then(phpReleases => {
request(options, (err, res, buffer) => {
if (err !== null) {
Expand Down
2 changes: 2 additions & 0 deletions services/travis/travis-php-version.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ module.exports = class TravisPhpVersion extends LegacyService {
}
const badgeData = getBadgeData('php', data)
getPhpReleases(githubApiProvider)
// Switch to async/await when this is refactored.
// eslint-disable-next-line promise/prefer-await-to-then
.then(phpReleases => {
request(options, (err, res, buffer) => {
if (err !== null) {
Expand Down

0 comments on commit d55e1c1

Please sign in to comment.