-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat(datasource): Add Nextcloud #37292
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
63f4178
2326256
e00b012
370be6c
7a8d0eb
9cf4eaf
6a81327
7aa8ad7
53996a4
09cb86f
94b848d
bed896f
aae6869
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import { getPkgReleases } from '..'; | ||
import { NextcloudDatasource } from '.'; | ||
import * as httpMock from '~test/http-mock'; | ||
|
||
describe('modules/datasource/nextcloud/index', () => { | ||
it(`no registryUrl`, async () => { | ||
const res = await getPkgReleases({ | ||
datasource: NextcloudDatasource.id, | ||
packageName: 'user_oidc', | ||
registryUrls: [], | ||
}); | ||
|
||
expect(res).toBeNull(); | ||
}); | ||
|
||
it(`no package`, async () => { | ||
const data = '[]'; | ||
|
||
httpMock.scope('https://custom.registry.com').get('/').reply(200, data); | ||
|
||
const res = await getPkgReleases({ | ||
datasource: NextcloudDatasource.id, | ||
packageName: 'user_oidc', | ||
registryUrls: ['https://custom.registry.com'], | ||
}); | ||
|
||
expect(res).toBeNull(); | ||
}); | ||
|
||
it(`package with no versions`, async () => { | ||
const data = ` | ||
[ | ||
{ | ||
"id": "user_oidc", | ||
"website": "https://github.com/nextcloud/user_oidc", | ||
"created": "2020-05-25T10:51:12.430005Z", | ||
"releases": [] | ||
} | ||
] | ||
`; | ||
|
||
httpMock.scope('https://custom.registry.com').get('/').reply(200, data); | ||
|
||
const res = await getPkgReleases({ | ||
datasource: NextcloudDatasource.id, | ||
packageName: 'user_oidc', | ||
registryUrls: ['https://custom.registry.com'], | ||
}); | ||
|
||
expect(res?.homepage).toBeUndefined(); | ||
expect(res?.registryUrl).toBe('https://custom.registry.com'); | ||
|
||
expect(res?.releases).toBeEmpty(); | ||
}); | ||
|
||
it.each([ | ||
{ | ||
website: 'https://github.com/nextcloud/user_oidc', | ||
changelogUrl: 'https://github.com/nextcloud-releases/user_oidc', | ||
}, | ||
{ | ||
website: 'https://custom.app', | ||
changelogUrl: 'https://custom.app', | ||
}, | ||
])( | ||
'package with website %s returns %s', | ||
async ({ website, changelogUrl }) => { | ||
const data = ` | ||
[ | ||
{ | ||
"id": "user_oidc", | ||
"website": "${website}", | ||
"created": "2020-05-25T10:51:12.430005Z", | ||
"releases": [ | ||
{ | ||
"version": "7.3.0", | ||
"created": "2025-07-25T09:41:26.318411Z", | ||
"isNightly": false, | ||
"translations": { | ||
"en": { | ||
"changelog": "testChangelog" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
`; | ||
|
||
httpMock.scope('https://custom.registry.com').get('/').reply(200, data); | ||
|
||
const res = await getPkgReleases({ | ||
datasource: NextcloudDatasource.id, | ||
packageName: 'user_oidc', | ||
registryUrls: ['https://custom.registry.com'], | ||
}); | ||
|
||
expect(res?.releases[0].changelogUrl).toBe(changelogUrl); | ||
}, | ||
); | ||
|
||
it(`package with changelog content and url`, async () => { | ||
const data = ` | ||
[ | ||
{ | ||
"id": "user_oidc", | ||
"website": "https://github.com/nextcloud/user_oidc", | ||
"created": "2020-05-25T10:51:12.430005Z", | ||
"releases": [ | ||
{ | ||
"version": "7.3.0", | ||
"created": "2025-07-25T09:41:26.318411Z", | ||
"isNightly": false, | ||
"translations": { | ||
"en": { | ||
"changelog": "testChangelog" | ||
} | ||
} | ||
}, | ||
{ | ||
"version": "7.2.0", | ||
"created": "2025-04-24T09:24:43.232337Z", | ||
"isNightly": true, | ||
"translations": { | ||
"en": { | ||
"changelog": "" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
`; | ||
|
||
httpMock.scope('https://custom.registry.com').get('/').reply(200, data); | ||
|
||
const res = await getPkgReleases({ | ||
datasource: NextcloudDatasource.id, | ||
packageName: 'user_oidc', | ||
registryUrls: ['https://custom.registry.com'], | ||
}); | ||
|
||
expect(res).toStrictEqual({ | ||
registryUrl: 'https://custom.registry.com', | ||
releases: [ | ||
{ | ||
changelogContent: undefined, | ||
changelogUrl: 'https://github.com/nextcloud-releases/user_oidc', | ||
isStable: false, | ||
registryUrl: 'https://custom.registry.com', | ||
releaseTimestamp: '2025-04-24T09:24:43.232Z', | ||
version: '7.2.0', | ||
}, | ||
{ | ||
changelogContent: 'testChangelog', | ||
changelogUrl: 'https://github.com/nextcloud-releases/user_oidc', | ||
isStable: true, | ||
registryUrl: 'https://custom.registry.com', | ||
releaseTimestamp: '2025-07-25T09:41:26.318Z', | ||
version: '7.3.0', | ||
}, | ||
], | ||
sourceUrl: 'https://github.com/nextcloud/user_oidc', | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { cache } from '../../../util/cache/package/decorator'; | ||
import { regEx } from '../../../util/regex'; | ||
import { asTimestamp } from '../../../util/timestamp'; | ||
import * as semanticVersioning from '../../versioning/semver'; | ||
import { Datasource } from '../datasource'; | ||
import type { GetReleasesConfig, ReleaseResult } from '../types'; | ||
import { Applications } from './schema'; | ||
|
||
export class NextcloudDatasource extends Datasource { | ||
static readonly id = 'nextcloud'; | ||
|
||
static readonly defaultTranslationLanguage = 'en'; | ||
bdovaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
override readonly defaultVersioning = semanticVersioning.id; | ||
bdovaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
private static readonly sourceUrlRegex = regEx( | ||
bdovaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/(?<prefix>.*github.com\/nextcloud)(?<suffix>\/.*)/, | ||
); | ||
|
||
constructor() { | ||
super(NextcloudDatasource.id); | ||
} | ||
|
||
@cache({ | ||
namespace: `datasource-${NextcloudDatasource.id}`, | ||
key: ({ registryUrl, packageName }: GetReleasesConfig) => | ||
`${registryUrl}:${packageName}`, | ||
}) | ||
async getReleases({ | ||
packageName, | ||
registryUrl, | ||
}: GetReleasesConfig): Promise<ReleaseResult | null> { | ||
if (!registryUrl) { | ||
return null; | ||
} | ||
|
||
const response = await this.http.getJson(registryUrl, Applications); | ||
|
||
const application = response.body.find((a) => a.id === packageName); | ||
|
||
if (!application) { | ||
return null; | ||
} | ||
|
||
const result: ReleaseResult = { | ||
releases: [], | ||
homepage: application.website, | ||
bdovaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
registryUrl, | ||
}; | ||
|
||
for (const release of application.releases) { | ||
const changelogContent = | ||
release.translations[NextcloudDatasource.defaultTranslationLanguage] | ||
bdovaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.changelog; | ||
const sourceUrlMatches = NextcloudDatasource.sourceUrlRegex.exec( | ||
application.website, | ||
); | ||
|
||
result.releases.push({ | ||
version: release.version, | ||
releaseTimestamp: asTimestamp(release.created), | ||
changelogContent: | ||
changelogContent.length > 0 ? changelogContent : undefined, | ||
changelogUrl: sourceUrlMatches?.groups | ||
bdovaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
? `${sourceUrlMatches.groups.prefix}-releases${sourceUrlMatches.groups.suffix}` | ||
: application.website, | ||
isStable: !release.isNightly, | ||
registryUrl, | ||
}); | ||
} | ||
|
||
return result; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
This datasource finds Nextcloud application updates from Nextcloud feeds. | ||
|
||
By default, Renovate has no default registry url for this datasource. You need to override the default behavior with the `registryUrls` config option. | ||
For example: | ||
|
||
```json | ||
{ | ||
"matchDatasources": ["nextcloud"], | ||
"registryUrls": [ | ||
"https://apps.nextcloud.com/api/v1/platform/30.0.0/apps.json" | ||
] | ||
} | ||
``` | ||
|
||
Additionally, if you want Renovate to automatically update the platform version, you can create a custom manager. | ||
For example: | ||
|
||
```json | ||
{ | ||
"customType": "regex", | ||
"managerFilePatterns": ["/(^|/)renovate.json$/"], | ||
"matchStrings": [ | ||
"https://apps.nextcloud.com/api/v1/platform/(?<currentValue>.*)/apps.json" | ||
bdovaz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
], | ||
"depNameTemplate": "nextcloud/server", | ||
"datasourceTemplate": "github-releases" | ||
} | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { z } from 'zod'; | ||
|
||
const Translation = z.object({ | ||
changelog: z.string(), | ||
}); | ||
|
||
export const ApplicationRelease = z.object({ | ||
created: z.string(), | ||
isNightly: z.boolean(), | ||
translations: z.record(z.string(), Translation), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. probably use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean? I'm not an expert in typescript or zod, can you give me an example? Thank you. |
||
version: z.string(), | ||
}); | ||
|
||
export const Application = z.object({ | ||
id: z.string(), | ||
releases: z.array(ApplicationRelease), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
website: z.string(), | ||
}); | ||
|
||
export const Applications = z.array(Application); |
Uh oh!
There was an error while loading. Please reload this page.