Skip to content

Commit

Permalink
ci: replace semantic commit checks with new workflow (#715)
Browse files Browse the repository at this point in the history
* ci: replace semantic commit checks with new workflow

* style: fix prettier errors

* style: fix linting errors
  • Loading branch information
ismay authored Jun 8, 2022
1 parent df95381 commit ede728c
Show file tree
Hide file tree
Showing 61 changed files with 713 additions and 315 deletions.
4 changes: 0 additions & 4 deletions .github/semantic.yml

This file was deleted.

32 changes: 32 additions & 0 deletions .github/workflows/dhis2-verify-commits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: 'dhis2: verify (commits)'

on:
pull_request:
types: ['opened', 'edited', 'reopened', 'synchronize']

jobs:
lint-pr-title:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: c-hive/gha-yarn-cache@v1
- run: yarn install --frozen-lockfile
- id: commitlint
run: echo ::set-output name=config_path::$(node -e "process.stdout.write(require('@dhis2/cli-style').config.commitlint)")
- uses: JulienKode/[email protected]
with:
configuration-path: ${{ steps.commitlint.outputs.config_path }}

lint-commits:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: c-hive/gha-yarn-cache@v1
- run: yarn install --frozen-lockfile
- id: commitlint
run: echo ::set-output name=config_path::$(node -e "process.stdout.write(require('@dhis2/cli-style').config.commitlint)")
- uses: wagoid/commitlint-github-action@v4
with:
configFile: ${{ steps.commitlint.outputs.config_path }}
6 changes: 3 additions & 3 deletions adapter/src/components/Alerts.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import React, { useState, useEffect } from 'react'
const Alerts = () => {
const alertManagerAlerts = useAlerts()
const [alertStackAlerts, setAlertStackAlerts] = useState(alertManagerAlerts)
const removeAlertStackAlert = id =>
const removeAlertStackAlert = (id) =>
setAlertStackAlerts(
alertStackAlerts.filter(
alertStackAlert => alertStackAlert.id !== id
(alertStackAlert) => alertStackAlert.id !== id
)
)

Expand All @@ -42,7 +42,7 @@ const Alerts = () => {
onHidden={() => {
onHidden && onHidden()
removeAlertStackAlert(id)
if (alertManagerAlerts.some(a => a.id === id)) {
if (alertManagerAlerts.some((a) => a.id === id)) {
remove()
}
}}
Expand Down
4 changes: 2 additions & 2 deletions adapter/src/components/ErrorBoundary.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import i18n from '@dhis2/d2-i18n'
import cx from 'classnames'
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import buttonStyles from './styles/Button.style'
import styles from './styles/ErrorBoundary.style'
import buttonStyles from './styles/Button.style.js'
import styles from './styles/ErrorBoundary.style.js'

// In order to avoid using @dhis2/ui components in the error boundary - as anything
// that breaks within it will not be caught properly - we define a component
Expand Down
14 changes: 7 additions & 7 deletions adapter/src/components/LoginModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
InputField,
} from '@dhis2/ui'
import React, { useState } from 'react'
import i18n from '../locales'
import { post } from '../utils/api'
import i18n from '../locales/index.js'
import { post } from '../utils/api.js'

const staticUrl = process.env.REACT_APP_DHIS2_BASE_URL

Expand All @@ -20,9 +20,9 @@ export const LoginModal = () => {
const [password, setPassword] = useState('')
const [isDirty, setIsDirty] = useState(false)

const isValid = val => val && val.length >= 2
const isValid = (val) => val && val.length >= 2

const onSubmit = async e => {
const onSubmit = async (e) => {
e.preventDefault()
setIsDirty(true)
if (isValid(server) && isValid(username) && isValid(password)) {
Expand Down Expand Up @@ -61,7 +61,7 @@ export const LoginModal = () => {
name="server"
type="text"
value={server}
onChange={input => setServer(input.value)}
onChange={(input) => setServer(input.value)}
/>
)}

Expand All @@ -72,7 +72,7 @@ export const LoginModal = () => {
name="j_username"
type="text"
value={username}
onChange={input => setUsername(input.value)}
onChange={(input) => setUsername(input.value)}
/>

<InputField
Expand All @@ -82,7 +82,7 @@ export const LoginModal = () => {
name="j_password"
type="password"
value={password}
onChange={input => setPassword(input.value)}
onChange={(input) => setPassword(input.value)}
/>
</ModalContent>

Expand Down
4 changes: 2 additions & 2 deletions adapter/src/components/PWAUpdateManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useState, useEffect } from 'react'
import i18n from '../locales'
import i18n from '../locales/index.js'

function ConfirmReloadModal({ clientsCount, onCancel, onConfirm }) {
return (
Expand Down Expand Up @@ -77,7 +77,7 @@ export default function PWAUpdateManager({ offlineInterface }) {
setConfirmReloadModalOpen(true)
}
})
.catch(reason => {
.catch((reason) => {
// Didn't get clients info
console.warn(reason)
// Go ahead with confirmation modal with `null` as clientsCount
Expand Down
6 changes: 3 additions & 3 deletions adapter/src/components/ServerVersionProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ export const ServerVersionProvider = ({
return
}

setState(state => (state.loading ? state : { loading: true }))
setState((state) => (state.loading ? state : { loading: true }))
const request = get(`${url}/api/system/info`)
request
.then(systemInfo => {
.then((systemInfo) => {
setState({ loading: false, systemInfo })
})
.catch(e => {
.catch((e) => {
setState({ loading: false, error: e })
})

Expand Down
2 changes: 1 addition & 1 deletion adapter/src/components/__tests__/ErrorBoundary.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { shallow } from 'enzyme'
import React from 'react'
import { ErrorBoundary } from '../ErrorBoundary'
import { ErrorBoundary } from '../ErrorBoundary.js'

const Something = () => {
// Placeholder
Expand Down
4 changes: 2 additions & 2 deletions adapter/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { checkForSWUpdateAndReload, OfflineInterface } from '@dhis2/pwa'
import PropTypes from 'prop-types'
import React from 'react'
import { AppWrapper } from './components/AppWrapper.js'
import { ErrorBoundary } from './components/ErrorBoundary'
import { ServerVersionProvider } from './components/ServerVersionProvider'
import { ErrorBoundary } from './components/ErrorBoundary.js'
import { ServerVersionProvider } from './components/ServerVersionProvider.js'

const offlineInterface = new OfflineInterface()

Expand Down
6 changes: 3 additions & 3 deletions adapter/src/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const request = (url, options) => {
},
signal: abortController.signal,
})
.then(response => {
.then((response) => {
if (response.status !== 200) {
reject('Request failed', response.statusText)
return
Expand All @@ -23,7 +23,7 @@ const request = (url, options) => {
resolve(response.text())
}
})
.catch(e => {
.catch((e) => {
console.error('Network error: ', e)
reject('Network error')
})
Expand All @@ -33,7 +33,7 @@ const request = (url, options) => {
return promise
}

export const get = url => request(url, { method: 'GET' })
export const get = (url) => request(url, { method: 'GET' })
export const post = (url, body) =>
request(url, {
method: 'POST',
Expand Down
2 changes: 1 addition & 1 deletion adapter/src/utils/parseServerVersion.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const parseServerVersion = versionString => {
export const parseServerVersion = (versionString) => {
const [mainVersion, tag] = versionString?.split('-') || []
const [major, minor, patch] = mainVersion?.split('.') || []

Expand Down
6 changes: 3 additions & 3 deletions adapter/src/utils/useLocale.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import { useState, useEffect } from 'react'

i18n.setDefaultNamespace('default')

const simplifyLocale = locale => {
const simplifyLocale = (locale) => {
const idx = locale.indexOf('-')
if (idx === -1) {
return locale
}
return locale.substr(0, idx)
}

const setGlobalLocale = locale => {
const setGlobalLocale = (locale) => {
if (locale !== 'en' && locale !== 'en-us') {
import(
/* webpackChunkName: "moment-locales/[request]" */ `moment/locale/${locale}`
Expand All @@ -27,7 +27,7 @@ const setGlobalLocale = locale => {
i18n.changeLanguage(simplifiedLocale)
}

export const useLocale = locale => {
export const useLocale = (locale) => {
const [result, setResult] = useState(undefined)
useEffect(() => {
if (!locale) {
Expand Down
2 changes: 1 addition & 1 deletion adapter/src/utils/useVerifyLatestUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function useVerifyLatestUser() {
const { pwaEnabled } = useConfig()
const [finished, setFinished] = useState(false)
const { loading, error } = useDataQuery(USER_QUERY, {
onComplete: async data => {
onComplete: async (data) => {
const latestUserId = localStorage.getItem(LATEST_USER_KEY)
const currentUserId = data.user.id
if (currentUserId !== latestUserId) {
Expand Down
2 changes: 1 addition & 1 deletion cli/config/makeBabelConfig.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const browserTargets = require('./.browserlistrc')
const jestTargets = { node: 'current' }

const getBabelModuleType = moduleType => {
const getBabelModuleType = (moduleType) => {
switch (moduleType) {
case 'cjs':
case 'commonjs':
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const handler = async ({ cwd }) => {
const dirsToClean = [paths.d2, paths.buildOutput]

reporter.info('Cleaning intermediate directories and build output...')
dirsToClean.forEach(dir => {
dirsToClean.forEach((dir) => {
reporter.print(' * ' + dir)
fs.removeSync(dir)
})
Expand Down
6 changes: 3 additions & 3 deletions cli/src/commands/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const dumpHttpError = (message, response) => {
reporter.debugErr('Error details', response.data)
}

const promptForDhis2Config = async params => {
const promptForDhis2Config = async (params) => {
if (
process.env.CI &&
(!params.baseUrl || !params.username || !params.password)
Expand All @@ -36,7 +36,7 @@ const promptForDhis2Config = async params => {
)
}

const isValidUrl = input =>
const isValidUrl = (input) =>
input && input.length && input.match(/^https?:\/\/[^/.]+/)

const responses = await inquirer.prompt([
Expand All @@ -45,7 +45,7 @@ const promptForDhis2Config = async params => {
name: 'baseUrl',
message: 'DHIS2 instance URL:',
when: () => !params.baseUrl,
validate: input =>
validate: (input) =>
isValidUrl(input)
? true
: 'Please enter a valid URL, it must start with http:// or https://',
Expand Down
12 changes: 6 additions & 6 deletions cli/src/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ const makePaths = require('../lib/paths')

const ignorePatterns = ['node_modules', '.d2', 'src/locales', 'build']

const parseGitignore = gitignoreFile => {
const parseGitignore = (gitignoreFile) => {
const newSection = { name: 'DHIS2 Platform', patterns: [] }
if (fs.existsSync(gitignoreFile)) {
const content = fs.readFileSync(gitignoreFile)
const parsed = gitignore.parse(content)

const existingSection = parsed.sections.filter(
section => section.name === newSection.name
(section) => section.name === newSection.name
)[0]

if (existingSection) {
newSection.patterns = existingSection.patterns
}

ignorePatterns.forEach(pattern => {
ignorePatterns.forEach((pattern) => {
if (!parsed.patterns.includes(pattern)) {
newSection.patterns.push(pattern)
}
Expand All @@ -36,9 +36,9 @@ const parseGitignore = gitignoreFile => {

const defaultSection = {
name: null,
patterns: parsed.patterns.filter(pattern => {
patterns: parsed.patterns.filter((pattern) => {
if (
parsed.sections.some(section =>
parsed.sections.some((section) =>
section.patterns.includes(pattern)
)
) {
Expand All @@ -57,7 +57,7 @@ const parseGitignore = gitignoreFile => {
}

const writeGitignore = (gitignoreFile, sections) => {
const format = section => {
const format = (section) => {
if (section.name === null && section.patterns.length) {
return section.patterns.join('\n') + '\n\n'
}
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports.command = 'pack [source]'

exports.describe = 'Create a .zip archive of a built application'

exports.builder = yargs =>
exports.builder = (yargs) =>
yargs
.positional('source', {
describe: 'The source directory to pack relative to cwd.',
Expand Down Expand Up @@ -39,7 +39,7 @@ exports.builder = yargs =>
defaultDescription: '${config.version}',
})

exports.handler = async argv => {
exports.handler = async (argv) => {
const {
cwd = process.cwd(),
source,
Expand Down
Loading

0 comments on commit ede728c

Please sign in to comment.