Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add script to generate core types (from shipped apps) #14366

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .github/workflows/update-nextcloud-openapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: MIT

name: Update nextcloud/openapi

on:
workflow_dispatch:
schedule:
- cron: "5 4 * * 0"

jobs:
update-nextcloud-openapi:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
branches: ['main', 'master', 'stable31', 'stable30']

name: Update Nextcloud OpenAPI types from core

steps:
- name: Set app env
run: |
# Split and keep last
echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV
- name: Checkout server
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
with:
submodules: true
repository: nextcloud/server
ref: ${{ matrix.server-versions }}

- name: Checkout app
uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6
with:
path: apps/${{ env.APP_NAME }}
ref: ${{ matrix.branches }}

- name: Read package.json node and npm engines version
uses: skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3
id: versions
with:
fallbackNode: '^20'
fallbackNpm: '^10'

- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
node-version: ${{ steps.versions.outputs.nodeVersion }}

- name: Set up npm ${{ steps.versions.outputs.npmVersion }}
run: npm i -g 'npm@${{ steps.versions.outputs.npmVersion }}'

- name: Install dependencies & generate types
working-directory: apps/${{ env.APP_NAME }}
env:
CYPRESS_INSTALL_BINARY: 0
PUPPETEER_SKIP_DOWNLOAD: true
run: |
npm ci
npm run typescript:generate-core-types --if-present
- name: Create Pull Request
if: steps.checkout.outcome == 'success'
uses: peter-evans/create-pull-request@c5a7806660adbe173f04e3e038b0ccdcd758773c # v6.1.0
with:
token: ${{ secrets.COMMAND_BOT_PAT }}
commit-message: 'chore(ts): update OpenAPI types from core'
committer: GitHub <[email protected]>
author: nextcloud-command <[email protected]>
signoff: true
branch: 'automated/noid/${{ matrix.branches }}-update-nextcloud-openapi'
title: '[${{ matrix.branches }}] Update Nextcloud OpenAPI types'
body: |
Auto-generated update of Nextcloud OpenAPI types
labels: |
dependencies
3. to review
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"serve": "node --max-old-space-size=4096 ./node_modules/webpack/bin/webpack.js serve --node-env development --progress --allowed-hosts all",
"typescript:check": "vue-tsc --noEmit",
"typescript:generate": "npx openapi-typescript -t",
"typescript:generate-core-types": "./src/types/generate-core-types.sh",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --coverage",
Expand Down
10 changes: 5 additions & 5 deletions src/components/RightSidebar/SearchMessages/SearchMessagesTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { ATTENDEE } from '../../../constants.ts'
import { searchMessages } from '../../../services/coreService.ts'
import { EventBus } from '../../../services/EventBus.ts'
import type {
CoreUnifiedSearchResultEntry,
UnifiedSearchResultEntry,
UserFilterObject,
SearchMessagePayload,
UnifiedSearchResponse,
Expand All @@ -56,7 +56,7 @@ const searchBox = ref<InstanceType<typeof SearchBox> | null>(null)
const { initializeNavigation, resetNavigation } = useArrowNavigation(searchMessagesTab, searchBox)

const isFocused = ref(false)
const searchResults = ref<(CoreUnifiedSearchResultEntry &
const searchResults = ref<(UnifiedSearchResultEntry &
{
to: {
name: string;
Expand Down Expand Up @@ -206,8 +206,8 @@ async function fetchSearchResults(isNew = true): Promise<void> {
})

const data = response?.data?.ocs?.data
if (data?.entries.length > 0) {
let entries = data?.entries
if (data && data.entries.length > 0) {
let entries = data.entries as UnifiedSearchResultEntry[]

isSearchExhausted.value = entries.length < searchLimit.value
searchCursor.value = data.cursor
Expand All @@ -220,7 +220,7 @@ async function fetchSearchResults(isNew = true): Promise<void> {
}
}

searchResults.value = searchResults.value.concat(entries.map((entry : CoreUnifiedSearchResultEntry) => {
searchResults.value = searchResults.value.concat(entries.map((entry: UnifiedSearchResultEntry) => {
return {
...entry,
to: {
Expand Down
11 changes: 9 additions & 2 deletions src/services/coreService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { generateOcsUrl } from '@nextcloud/router'
import { getTalkConfig, hasTalkFeature } from './CapabilitiesManager.ts'
import { SHARE } from '../constants.ts'
import type {
AutocompleteParams,
AutocompleteResponse,
TaskProcessingResponse,
UnifiedSearchResponse,
SearchMessagePayload,
Expand Down Expand Up @@ -36,7 +38,12 @@ type SearchPayload = {
* @param [payload.forceTypes] Whether to force some types to be included in query
* @param options options
*/
const autocompleteQuery = async function({ searchText, token = 'new', onlyUsers = false, forceTypes = [] }: SearchPayload, options: object) {
const autocompleteQuery = async function({
searchText,
token = 'new',
onlyUsers = false,
forceTypes = [],
}: SearchPayload, options: object): AutocompleteResponse {
const shareTypes: ShareType[] = onlyUsers
? [SHARE.TYPE.USER]
: [
Expand All @@ -54,7 +61,7 @@ const autocompleteQuery = async function({ searchText, token = 'new', onlyUsers
itemType: 'call',
itemId: token,
shareTypes: shareTypes.concat(forceTypes),
},
} as AutocompleteParams,
})
}

Expand Down
3 changes: 2 additions & 1 deletion src/services/settingsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
setSipSettingsResponse,
setUserSettingsParams,
setUserSettingsResponse,
UserPreferencesParams,
UserPreferencesResponse,
} from '../types/index.ts'

Expand Down Expand Up @@ -100,7 +101,7 @@ const setConversationsListStyle = async function(value: string) {
const setUserConfig = async function(appId: string, configKey: string, configValue: string): UserPreferencesResponse {
return axios.post(generateOcsUrl('apps/provisioning_api/api/v1/config/users/{appId}/{configKey}', { appId, configKey }), {
configValue,
})
} as UserPreferencesParams)
}

export {
Expand Down
31 changes: 31 additions & 0 deletions src/types/generate-core-types.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
#
# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: AGPL-3.0-only
#

# By default is expected that pwd returns <server_directory>/<apps or apps-extra>/spreed
SERVER_DIR="${1:-$(dirname $(dirname $(pwd)))}"
TYPES_DIR="$(pwd)/src/types"
CORE_TYPES_OUTPUT_DIR="$TYPES_DIR/openapi/core"
TEMP_DIR="$TYPES_DIR/tmp"

# Create the temporary directory if it doesn't exist
mkdir -p "$CORE_TYPES_OUTPUT_DIR"
mkdir -p "$TEMP_DIR"

# Find and copy openapi.json files, then translate to ts types
generate_ts_files() {
local full_path=$1 # Full path passed as an argument
local new_name="openapi_${full_path#apps/}"

find "$SERVER_DIR/$full_path" -maxdepth 1 -name "openapi.json" -exec sh -c 'cp "$1" "$2/$3"' _ {} "$TEMP_DIR" "$new_name.json" \;
npx openapi-typescript --redocly $TYPES_DIR "$TEMP_DIR/$new_name.json" -t -o "$CORE_TYPES_OUTPUT_DIR/$new_name.ts"
}

generate_ts_files "core"
generate_ts_files "apps/files_sharing"
generate_ts_files "apps/dav"
generate_ts_files "apps/provisioning_api"

rm -rf "$TEMP_DIR"
Loading
Loading