Skip to content
Merged
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
91 changes: 23 additions & 68 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,98 +14,53 @@
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run linter
run: npm run lint
- run: npm ci
- run: npm run lint

test:
name: Test
runs-on: ubuntu-latest

outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- run: npm ci
- run: npm run test -- --coverage
- id: version
run: echo "version=$(node -p "require('./manifest.json').version")" >> $GITHUB_OUTPUT

- name: Install dependencies
run: npm ci

- name: Run tests
run: npm run test

- name: Run tests with coverage
run: npm run test -- --coverage

build:
name: Build
artifact:
name: Package Artifact
runs-on: ubuntu-latest
needs: [lint, test]

needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Build plugin
run: npm run build

- name: Check build artifacts
run: |
if [ ! -f main.js ]; then
echo "Error: main.js not found"
exit 1
fi
if [ ! -f manifest.json ]; then
echo "Error: manifest.json not found"
exit 1
fi
if [ ! -f styles.css ]; then
echo "Error: styles.css not found"
exit 1
fi
echo "✓ All build artifacts present"

- name: Get version from manifest
id: version
run: echo "version=$(node -p "require('./manifest.json').version")" >> $GITHUB_OUTPUT

- run: npm ci
- run: npm run build
- name: Create plugin package
run: |
VERSION=${{ needs.test.outputs.version }}
BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}
BRANCH_NAME_SAFE=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9._-]/-/g')
ZIP_NAME="git-files-sync-${{ steps.version.outputs.version }}-${BRANCH_NAME_SAFE}.zip"
ZIP_NAME="git-files-sync-${VERSION}-${BRANCH_NAME_SAFE}.zip"
zip -j "$ZIP_NAME" main.js manifest.json styles.css
echo "ZIP_NAME=$ZIP_NAME" >> $GITHUB_ENV

- name: Upload build artifacts
uses: actions/upload-artifact@v4
- uses: actions/upload-artifact@v4
with:
name: plugin-build-${{ steps.version.outputs.version }}-${{ github.sha }}
name: plugin-build-${{ needs.test.outputs.version }}-${{ github.sha }}
path: ${{ env.ZIP_NAME }}
retention-days: 7

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
28 changes: 0 additions & 28 deletions .github/workflows/lint.yml

This file was deleted.

55 changes: 13 additions & 42 deletions .github/workflows/semantic-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,71 +15,42 @@ jobs:
lint:
name: Lint
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run linter
run: npm run lint
- run: npm ci
- run: npm run lint

test:
name: Test
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run tests
run: npm run test

- name: Run tests with coverage
run: npm run test -- --coverage
- run: npm ci
- run: npm run test -- --coverage

release:
name: Build and Release
runs-on: ubuntu-latest
needs: [lint, test]

steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false

- name: Setup Node.js
uses: actions/setup-node@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Build plugin
run: npm run build

- name: Release
env:
- run: npm ci
- run: npm run build
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx semantic-release
47 changes: 47 additions & 0 deletions .github/workflows/sonarqube.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Build
on:
push:
branches:
- master
- main
pull_request:
types: [opened, synchronize, reopened]

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'npm'
- run: npm ci
- run: npm run test -- --coverage
- run: npm run build

# Upload coverage for the next job
- name: Upload coverage
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage/

sonar:
Comment on lines +12 to +31
name: SonarQube
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download coverage
uses: actions/download-artifact@v4
with:
name: coverage-report
path: coverage/
- name: SonarQube Scan
uses: SonarSource/sonarqube-scan-action@v7.1.0
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Comment on lines +32 to +47
14 changes: 2 additions & 12 deletions eslint.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,15 @@ export default tseslint.config(
projectService: {
allowDefaultProject: [
'eslint.config.js',
'manifest.json',
'vitest.config.ts',
'manifest.json'
]
},
ttsconfigRootDir: import.meta.dirname,
tsconfigRootDir: import.meta.dirname,
extraFileExtensions: ['.json']
},
},
rules: {
'no-alert': 'off', // Allow confirm dialogs for user confirmation
'@typescript-eslint/await-thenable': 'off', // Settings methods may not return promises
}
},
...obsidianmd.configs.recommended,
{
rules: {
'obsidianmd/ui/sentence-case': 'off',
}
},
globalIgnores([
"node_modules",
"dist",
Expand Down
14 changes: 14 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sonar.projectKey=firstsun-dev_git-files-sync
sonar.organization=firstsun-dev


# This is the name and version displayed in the SonarCloud UI.
#sonar.projectName=git-files-sync
#sonar.projectVersion=1.0


# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
#sonar.sources=.

# Encoding of the source code. Default is default system encoding
#sonar.sourceEncoding=UTF-8
8 changes: 3 additions & 5 deletions src/logic/sync-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,11 @@ export class SyncManager {
}

private async saveSettings() {
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-explicit-any */
// @ts-ignore - access private method to save settings
const plugin = (this.app as any).plugins?.plugins?.['git-file-sync'];
if (plugin) {
const plugins = (this.app as unknown as { plugins: { plugins: Record<string, { saveSettings: () => Promise<void> }> } }).plugins;
const plugin = plugins?.plugins?.['git-file-sync'];
if (plugin && typeof plugin.saveSettings === 'function') {
await plugin.saveSettings();
}
/* eslint-enable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-explicit-any */
}

async pushAllFiles(files: (TFile | string)[], onProgress?: (current: number, total: number, fileName: string) => void): Promise<{ success: number; failed: number; errors: Array<{ file: string; error: string }> }> {
Expand Down
12 changes: 8 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { GitServiceInterface } from './services/git-service-interface';
import { SyncManager } from './logic/sync-manager';
import { SyncStatusView, SYNC_STATUS_VIEW_TYPE } from './ui/SyncStatusView';
import { GitignoreManager } from './logic/gitignore-manager';
import { ConfirmModal } from './ui/ConfirmModal';

export default class GitLabFilesPush extends Plugin {
settings: GitLabFilesPushSettings;
Expand Down Expand Up @@ -40,7 +41,7 @@ export default class GitLabFilesPush extends Plugin {

const serviceName = this.settings.serviceType === 'gitlab' ? 'GitLab' : 'GitHub';

this.addRibbonIcon('upload-cloud', Platform.isMobile ? `Push` : `Push to ${serviceName}`, (evt: MouseEvent) => {
this.addRibbonIcon('upload-cloud', Platform.isMobile ? `Push` : `Push to ${serviceName}`, () => {
const activeView = this.app.workspace.getActiveViewOfType(MarkdownView);
if (activeView && activeView.file instanceof TFile) {
void this.sync.pushFile(activeView.file);
Expand Down Expand Up @@ -240,9 +241,12 @@ export default class GitLabFilesPush extends Plugin {

private showConfirmDialog(message: string): Promise<boolean> {
return new Promise((resolve) => {
// eslint-disable-next-line no-alert
const confirmed = confirm(message);
resolve(confirmed);
new ConfirmModal(
this.app,
message,
() => resolve(true),
() => resolve(false)
).open();
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/github-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export class GitHubService implements GitServiceInterface {
}
}

async listFiles(branch: string, path: string = ''): Promise<string[]> {
async listFiles(branch: string, _path: string = ''): Promise<string[]> {
const url = `https://api.github.com/repos/${this.owner}/${this.repo}/git/trees/${branch}?recursive=1`;

const response = await this.safeRequest({
Expand Down
Loading
Loading