Initiatives: add Project parameters (#1671)
Adding parameters to Project. Assumes we're loading an InitiativesDirectory. We're not including the local path here, as this is environment dependent. It should be passed as an ENV or CLI parameter instead.
This commit is contained in:
parent
1f41fc3003
commit
4d0a7fd60b
|
@ -1 +1 @@
|
||||||
[{"type":"sourcecred/project","version":"0.4.0"},{"discourseServer":null,"id":"sourcecred-test/example-github","identities":[],"repoIds":[{"name":"example-github","owner":"sourcecred-test"}]}]
|
[{"type":"sourcecred/project","version":"0.5.0"},{"discourseServer":null,"id":"sourcecred-test/example-github","identities":[],"initiatives":null,"repoIds":[{"name":"example-github","owner":"sourcecred-test"}]}]
|
|
@ -3,6 +3,7 @@
|
||||||
import base64url from "base64url";
|
import base64url from "base64url";
|
||||||
import {type RepoId} from "../plugins/github/repoId";
|
import {type RepoId} from "../plugins/github/repoId";
|
||||||
import {toCompat, fromCompat, type Compatible} from "../util/compat";
|
import {toCompat, fromCompat, type Compatible} from "../util/compat";
|
||||||
|
import {type ProjectParameters as Initiatives} from "../plugins/initiatives/params";
|
||||||
import {type Identity} from "../plugins/identity/identity";
|
import {type Identity} from "../plugins/identity/identity";
|
||||||
import {type DiscourseServer} from "../plugins/discourse/server";
|
import {type DiscourseServer} from "../plugins/discourse/server";
|
||||||
|
|
||||||
|
@ -24,17 +25,22 @@ export type ProjectId = string;
|
||||||
* the future (e.g. showing the last update time for each of the project's data
|
* the future (e.g. showing the last update time for each of the project's data
|
||||||
* dependencies).
|
* dependencies).
|
||||||
*/
|
*/
|
||||||
export type Project = ProjectV040;
|
export type Project = ProjectV050;
|
||||||
export type SupportedProject = ProjectV030 | ProjectV031 | ProjectV040;
|
export type SupportedProject =
|
||||||
|
| ProjectV030
|
||||||
|
| ProjectV031
|
||||||
|
| ProjectV040
|
||||||
|
| ProjectV050;
|
||||||
|
|
||||||
type ProjectV040 = {|
|
export type ProjectV050 = {|
|
||||||
+id: ProjectId,
|
+id: ProjectId,
|
||||||
|
+initiatives: Initiatives | null,
|
||||||
+repoIds: $ReadOnlyArray<RepoId>,
|
+repoIds: $ReadOnlyArray<RepoId>,
|
||||||
+discourseServer: DiscourseServer | null,
|
+discourseServer: DiscourseServer | null,
|
||||||
+identities: $ReadOnlyArray<Identity>,
|
+identities: $ReadOnlyArray<Identity>,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
const COMPAT_INFO = {type: "sourcecred/project", version: "0.4.0"};
|
const COMPAT_INFO = {type: "sourcecred/project", version: "0.5.0"};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new Project instance with default values.
|
* Creates a new Project instance with default values.
|
||||||
|
@ -50,6 +56,7 @@ export function createProject(p: $Shape<Project>): Project {
|
||||||
repoIds: [],
|
repoIds: [],
|
||||||
identities: [],
|
identities: [],
|
||||||
discourseServer: null,
|
discourseServer: null,
|
||||||
|
initiatives: null,
|
||||||
...p,
|
...p,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -72,13 +79,28 @@ export function encodeProjectId(id: ProjectId): string {
|
||||||
return base64url.encode(id);
|
return base64url.encode(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
const upgradeFrom030 = (p: ProjectV030 | ProjectV031): ProjectV040 => ({
|
const upgradeFrom040 = (p: ProjectV040): ProjectV050 => ({
|
||||||
...p,
|
...p,
|
||||||
discourseServer:
|
initiatives: null,
|
||||||
p.discourseServer != null ? {serverUrl: p.discourseServer.serverUrl} : null,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
type ProjectV031 = {|
|
export type ProjectV040 = {|
|
||||||
|
+id: ProjectId,
|
||||||
|
+repoIds: $ReadOnlyArray<RepoId>,
|
||||||
|
+discourseServer: DiscourseServer | null,
|
||||||
|
+identities: $ReadOnlyArray<Identity>,
|
||||||
|
|};
|
||||||
|
|
||||||
|
const upgradeFrom030 = (p: ProjectV030 | ProjectV031) =>
|
||||||
|
upgradeFrom040({
|
||||||
|
...p,
|
||||||
|
discourseServer:
|
||||||
|
p.discourseServer != null
|
||||||
|
? {serverUrl: p.discourseServer.serverUrl}
|
||||||
|
: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
export type ProjectV031 = {|
|
||||||
+id: ProjectId,
|
+id: ProjectId,
|
||||||
+repoIds: $ReadOnlyArray<RepoId>,
|
+repoIds: $ReadOnlyArray<RepoId>,
|
||||||
+discourseServer: {|
|
+discourseServer: {|
|
||||||
|
@ -88,7 +110,7 @@ type ProjectV031 = {|
|
||||||
+identities: $ReadOnlyArray<Identity>,
|
+identities: $ReadOnlyArray<Identity>,
|
||||||
|};
|
|};
|
||||||
|
|
||||||
type ProjectV030 = {|
|
export type ProjectV030 = {|
|
||||||
+id: ProjectId,
|
+id: ProjectId,
|
||||||
+repoIds: $ReadOnlyArray<RepoId>,
|
+repoIds: $ReadOnlyArray<RepoId>,
|
||||||
+discourseServer: {|
|
+discourseServer: {|
|
||||||
|
@ -101,4 +123,5 @@ type ProjectV030 = {|
|
||||||
const upgrades = {
|
const upgrades = {
|
||||||
"0.3.0": upgradeFrom030,
|
"0.3.0": upgradeFrom030,
|
||||||
"0.3.1": upgradeFrom030,
|
"0.3.1": upgradeFrom030,
|
||||||
|
"0.4.0": upgradeFrom040,
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,6 +8,9 @@ import {
|
||||||
type Project,
|
type Project,
|
||||||
encodeProjectId,
|
encodeProjectId,
|
||||||
createProject,
|
createProject,
|
||||||
|
type ProjectV040,
|
||||||
|
type ProjectV031,
|
||||||
|
type ProjectV030,
|
||||||
} from "./project";
|
} from "./project";
|
||||||
|
|
||||||
import {makeRepoId} from "../plugins/github/repoId";
|
import {makeRepoId} from "../plugins/github/repoId";
|
||||||
|
@ -20,12 +23,14 @@ describe("core/project", () => {
|
||||||
id: "foo/bar",
|
id: "foo/bar",
|
||||||
repoIds: [foobar],
|
repoIds: [foobar],
|
||||||
discourseServer: null,
|
discourseServer: null,
|
||||||
|
initiatives: null,
|
||||||
identities: [],
|
identities: [],
|
||||||
});
|
});
|
||||||
const p2: Project = deepFreeze({
|
const p2: Project = deepFreeze({
|
||||||
id: "@foo",
|
id: "@foo",
|
||||||
repoIds: [foobar, foozod],
|
repoIds: [foobar, foozod],
|
||||||
discourseServer: {serverUrl: "https://example.com"},
|
discourseServer: {serverUrl: "https://example.com"},
|
||||||
|
initiatives: {remoteUrl: "http://foo.bar/initiatives"},
|
||||||
identities: [
|
identities: [
|
||||||
{
|
{
|
||||||
username: "example",
|
username: "example",
|
||||||
|
@ -45,7 +50,7 @@ describe("core/project", () => {
|
||||||
});
|
});
|
||||||
it("should upgrade from 0.3.0 formatting", () => {
|
it("should upgrade from 0.3.0 formatting", () => {
|
||||||
// Given
|
// Given
|
||||||
const body = {
|
const body: ProjectV030 = {
|
||||||
id: "example-030",
|
id: "example-030",
|
||||||
repoIds: [foobar, foozod],
|
repoIds: [foobar, foozod],
|
||||||
discourseServer: {
|
discourseServer: {
|
||||||
|
@ -63,15 +68,18 @@ describe("core/project", () => {
|
||||||
const project = projectFromJSON(compat);
|
const project = projectFromJSON(compat);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
expect(project).toEqual({
|
expect(project).toEqual(
|
||||||
|
({
|
||||||
...body,
|
...body,
|
||||||
// It should strip the apiUsername field, keeping just serverUrl.
|
// It should strip the apiUsername field, keeping just serverUrl.
|
||||||
discourseServer: {serverUrl: "https://example.com"},
|
discourseServer: {serverUrl: "https://example.com"},
|
||||||
});
|
initiatives: null,
|
||||||
|
}: Project)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
it("should upgrade from 0.3.1 formatting", () => {
|
it("should upgrade from 0.3.1 formatting", () => {
|
||||||
// Given
|
// Given
|
||||||
const body = {
|
const body: ProjectV031 = {
|
||||||
id: "example-031",
|
id: "example-031",
|
||||||
repoIds: [foobar, foozod],
|
repoIds: [foobar, foozod],
|
||||||
discourseServer: {
|
discourseServer: {
|
||||||
|
@ -89,11 +97,39 @@ describe("core/project", () => {
|
||||||
const project = projectFromJSON(compat);
|
const project = projectFromJSON(compat);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
expect(project).toEqual({
|
expect(project).toEqual(
|
||||||
|
({
|
||||||
...body,
|
...body,
|
||||||
// It should strip the apiUsername field, keeping just serverUrl.
|
// It should strip the apiUsername field, keeping just serverUrl.
|
||||||
discourseServer: {serverUrl: "https://example.com"},
|
discourseServer: {serverUrl: "https://example.com"},
|
||||||
|
initiatives: null,
|
||||||
|
}: Project)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
it("should upgrade from 0.4.0 formatting", () => {
|
||||||
|
// Given
|
||||||
|
const body: ProjectV040 = {
|
||||||
|
id: "example-040",
|
||||||
|
repoIds: [foobar, foozod],
|
||||||
|
discourseServer: {serverUrl: "https://example.com"},
|
||||||
|
identities: [],
|
||||||
|
};
|
||||||
|
const compat = toCompat(
|
||||||
|
{type: "sourcecred/project", version: "0.4.0"},
|
||||||
|
body
|
||||||
|
);
|
||||||
|
|
||||||
|
// When
|
||||||
|
const project = projectFromJSON(compat);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
expect(project).toEqual(
|
||||||
|
({
|
||||||
|
...body,
|
||||||
|
// It should add a default initiatives field.
|
||||||
|
initiatives: null,
|
||||||
|
}: Project)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe("encodeProjectId", () => {
|
describe("encodeProjectId", () => {
|
||||||
|
@ -130,6 +166,7 @@ describe("core/project", () => {
|
||||||
expect(project).toEqual({
|
expect(project).toEqual({
|
||||||
id: projectShape.id,
|
id: projectShape.id,
|
||||||
discourseServer: null,
|
discourseServer: null,
|
||||||
|
initiatives: null,
|
||||||
repoIds: [],
|
repoIds: [],
|
||||||
identities: [],
|
identities: [],
|
||||||
});
|
});
|
||||||
|
@ -141,6 +178,7 @@ describe("core/project", () => {
|
||||||
id: "@foo",
|
id: "@foo",
|
||||||
repoIds: [foobar, foozod],
|
repoIds: [foobar, foozod],
|
||||||
discourseServer: {serverUrl: "https://example.com"},
|
discourseServer: {serverUrl: "https://example.com"},
|
||||||
|
initiatives: {remoteUrl: "http://foo.bar/initiatives"},
|
||||||
identities: [
|
identities: [
|
||||||
{
|
{
|
||||||
username: "example",
|
username: "example",
|
||||||
|
|
|
@ -37,6 +37,7 @@ describe("core/project_io", () => {
|
||||||
repoIds: [foobar, foozod],
|
repoIds: [foobar, foozod],
|
||||||
discourseServer: {serverUrl: "https://example.com"},
|
discourseServer: {serverUrl: "https://example.com"},
|
||||||
identities: [{username: "foo", aliases: ["github/foo", "discourse/foo"]}],
|
identities: [{username: "foo", aliases: ["github/foo", "discourse/foo"]}],
|
||||||
|
initiatives: {remoteUrl: "https://example.com/initiatives"},
|
||||||
});
|
});
|
||||||
|
|
||||||
it("setupProjectDirectory results in a loadable project", async () => {
|
it("setupProjectDirectory results in a loadable project", async () => {
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
// @flow
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options to add to Project spec.
|
||||||
|
* Assumes we're loading an InitiativesDirectory. We're not including the local
|
||||||
|
* path here, as this is environment dependent. It should be passed as an ENV
|
||||||
|
* or CLI parameter instead.
|
||||||
|
*/
|
||||||
|
export type ProjectParameters = {|
|
||||||
|
+remoteUrl: string,
|
||||||
|
|};
|
Loading…
Reference in New Issue