Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
fochoa8 authored Sep 30, 2024
2 parents f25c49a + 8079448 commit 776a328
Show file tree
Hide file tree
Showing 118 changed files with 2,313 additions and 1,233 deletions.
111 changes: 102 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ on:
push:
branches:
- main
- arch
- 'v5.*'
- 3.x
- 2.x

env:
FORCE_COLOR: 1
Expand Down Expand Up @@ -61,6 +58,23 @@ jobs:
echo "Setting BASE_COMMIT to $BASE_COMMIT"
echo "BASE_COMMIT=$BASE_COMMIT" >> $GITHUB_ENV
- name: Check user org membership
id: check_user_org_membership
if: github.event_name == 'pull_request'
run: |
echo "Looking up: ${{ github.event.pull_request.user.login }}"
ENCODED_USERNAME=$(printf '%s' '${{ github.event.pull_request.user.login }}' | jq -sRr @uri)
LOOKUP_USER=$(curl --write-out "%{http_code}" --silent --output /dev/null --location "https://api.github.com/orgs/tryghost/members/$ENCODED_USERNAME" --header "Authorization: Bearer ${{ secrets.CANARY_DOCKER_BUILD }}")
if [ "$LOOKUP_USER" == "204" ]; then
echo "User is in the org"
echo "is_member=true" >> $GITHUB_OUTPUT
else
echo "User is not in the org"
echo "is_member=false" >> $GITHUB_OUTPUT
fi
- name: Determine added packages
uses: dorny/[email protected]
id: added
Expand Down Expand Up @@ -179,9 +193,8 @@ jobs:
changed_any_code: ${{ steps.changed.outputs.any-code }}
changed_new_package: ${{ steps.added.outputs.new-package }}
base_commit: ${{ env.BASE_COMMIT }}
branch_name: ${{ github.ref_name }}
is_canary_branch: ${{ github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/arch') }}
is_main: ${{ env.IS_MAIN }}
member_is_in_org: ${{ steps.check_user_org_membership.outputs.is_member }}
has_browser_tests_label: ${{ github.event_name == 'pull_request' && contains(github.event.pull_request.labels.*.name, 'browser-tests') }}
dependency_cache_key: ${{ env.cachekey }}

Expand All @@ -193,7 +206,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 100
fetch-depth: 1000
- uses: actions/setup-node@v4
env:
FORCE_COLOR: 0
Expand Down Expand Up @@ -419,7 +432,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 100
fetch-depth: 1000
- uses: actions/setup-node@v4
env:
FORCE_COLOR: 0
Expand Down Expand Up @@ -950,18 +963,98 @@ jobs:
]
name: Canary
runs-on: ubuntu-latest
if: always() && needs.job_setup.outputs.is_canary_branch == 'true' && needs.job_setup.result == 'success' && needs.job_required_tests.result == 'success'
if: |
always()
&& needs.job_setup.result == 'success'
&& needs.job_required_tests.result == 'success'
&& (
needs.job_setup.outputs.is_main == 'true'
|| (
github.event_name == 'pull_request'
&& needs.job_setup.outputs.member_is_in_org == 'true'
&& contains(github.event.pull_request.labels.*.name, 'deploy-to-staging')
)
)
steps:
- name: Output needs (for debugging)
run: echo "${{ toJson(needs) }}"

- name: Compute branch name (push)
if: github.event_name == 'push'
run: echo "branch_name=${{ github.ref_name }}" >> $GITHUB_ENV

- name: Compute branch name (pull_request)
if: github.event_name == 'pull_request'
run: echo "branch_name=${{ github.ref }}" >> $GITHUB_ENV

- name: Invoke build
uses: aurelien-baudet/workflow-dispatch@v2
with:
token: ${{ secrets.CANARY_DOCKER_BUILD }}
workflow: .github/workflows/deploy.yml
ref: 'refs/heads/main'
repo: TryGhost/Ghost-Moya
inputs: '{"version":"canary","environment":"staging","version_extra":"${{ needs.job_setup.outputs.branch_name }}"}'
inputs: '{"version":"canary","environment":"staging","version_extra":"${{ env.branch_name }}"}'
wait-for-completion-timeout: 25m
wait-for-completion-interval: 30s

publish_admin_x_activitypub:
needs: [
job_setup,
job_lint,
job_unit-tests
]
name: Publish @tryghost/admin-x-activitypub
runs-on: ubuntu-latest
if: always() && needs.job_setup.result == 'success' && needs.job_lint.result == 'success' && needs.job_unit-tests.result == 'success' && needs.job_setup.outputs.is_main == 'true'
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18.12.1'

- name: Restore caches
uses: ./.github/actions/restore-cache
env:
DEPENDENCY_CACHE_KEY: ${{ needs.job_setup.outputs.dependency_cache_key }}

- name: Build the package
run: yarn run nx build @tryghost/admin-x-activitypub

- name: Check if version changed
id: version_check
working-directory: apps/admin-x-activitypub
run: |
CURRENT_VERSION=$(cat package.json | jq -r .version)
PUBLISHED_VERSION=$(npm show @tryghost/admin-x-activitypub version || echo "0.0.0")
echo "Current version: $CURRENT_VERSION"
echo "Published version: $PUBLISHED_VERSION"
if [ "$CURRENT_VERSION" = "$PUBLISHED_VERSION" ]; then
echo "Version is unchanged."
echo "version_changed=false" >> $GITHUB_ENV
else
echo "Version has changed."
echo "version_changed=true" >> $GITHUB_ENV
fi
- name: Configure .npmrc
run: |
echo "@tryghost:registry=https://registry.npmjs.org/" >> ~/.npmrc
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc
- name: Publish to npm
if: env.version_changed == 'true'
working-directory: apps/admin-x-activitypub
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm publish --access public

- name: Purge jsdelivr cache
if: env.version_changed == 'true'
uses: gacts/purge-jsdelivr-cache@v1
with:
url: |
https://cdn.jsdelivr.net/npm/@tryghost/admin-x-activitypub@0/dist/admin-x-activitypub.js
17 changes: 10 additions & 7 deletions apps/admin-x-activitypub/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tryghost/admin-x-activitypub",
"version": "0.0.0",
"version": "0.1.0",
"license": "MIT",
"repository": {
"type": "git",
Expand All @@ -14,7 +14,7 @@
],
"main": "./dist/admin-x-activitypub.umd.cjs",
"module": "./dist/admin-x-activitypub.js",
"private": true,
"private": false,
"scripts": {
"dev": "vite build --watch",
"dev:start": "vite",
Expand All @@ -31,15 +31,10 @@
"devDependencies": {
"@playwright/test": "1.46.1",
"@testing-library/react": "14.3.1",
"@tryghost/admin-x-design-system": "0.0.0",
"@tryghost/admin-x-framework": "0.0.0",
"@types/jest": "29.5.12",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"@radix-ui/react-form": "0.0.3",
"jest": "29.7.0",
"react": "18.3.1",
"react-dom": "18.3.1",
"ts-jest": "29.1.5"
},
"nx": {
Expand Down Expand Up @@ -67,5 +62,13 @@
]
}
}
},
"dependencies": {
"@radix-ui/react-form": "0.0.3",
"use-debounce": "10.0.3",
"@tryghost/admin-x-design-system": "0.0.0",
"@tryghost/admin-x-framework": "0.0.0",
"react": "18.3.1",
"react-dom": "18.3.1"
}
}
43 changes: 43 additions & 0 deletions apps/admin-x-activitypub/src/api/activitypub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,47 @@ describe('ActivityPubAPI', function () {
expect(actual).toEqual(expected);
});
});

describe('search', function () {
test('It returns the results of the search', async function () {
const fakeFetch = Fetch({
'https://auth.api/': {
response: JSONResponse({
identities: [{
token: 'fake-token'
}]
})
},
'https://activitypub.api/.ghost/activitypub/actions/search?query=%40foo%40bar.baz': {
response: JSONResponse({
profiles: [
{
handle: '@[email protected]',
name: 'Foo Bar'
}
]
})
}
});

const api = new ActivityPubAPI(
new URL('https://activitypub.api'),
new URL('https://auth.api'),
'index',
fakeFetch
);

const actual = await api.search('@[email protected]');
const expected = {
profiles: [
{
handle: '@[email protected]',
name: 'Foo Bar'
}
]
};

expect(actual).toEqual(expected);
});
});
});
32 changes: 32 additions & 0 deletions apps/admin-x-activitypub/src/api/activitypub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ export type Actor = any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Activity = any;

export interface ProfileSearchResult {
actor: Actor;
handle: string;
followerCount: number;
isFollowing: boolean;
posts: Activity[];
}

export interface SearchResults {
profiles: ProfileSearchResult[];
}

export class ActivityPubAPI {
constructor(
private readonly apiUrl: URL,
Expand Down Expand Up @@ -280,4 +292,24 @@ export class ActivityPubAPI {
const json = await this.fetchJSON(this.userApiUrl);
return json;
}

get searchApiUrl() {
return new URL('.ghost/activitypub/actions/search', this.apiUrl);
}

async search(query: string): Promise<SearchResults> {
const url = this.searchApiUrl;

url.searchParams.set('query', query);

const json = await this.fetchJSON(url, 'GET');

if (json && 'profiles' in json) {
return json as SearchResults;
}

return {
profiles: []
};
}
}
19 changes: 10 additions & 9 deletions apps/admin-x-activitypub/src/components/Activities.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import NiceModal from '@ebay/nice-modal-react';
import React, {useEffect, useRef} from 'react';
import {Button, LoadingIndicator, NoValueLabel} from '@tryghost/admin-x-design-system';

import NiceModal from '@ebay/nice-modal-react';
import {LoadingIndicator, NoValueLabel} from '@tryghost/admin-x-design-system';

import APAvatar, {AvatarBadge} from './global/APAvatar';
import ActivityItem, {type Activity} from './activities/ActivityItem';
import ArticleModal from './feed/ArticleModal';
import FollowButton from './global/FollowButton';
import MainNavigation from './navigation/MainNavigation';

import getUsername from '../utils/get-username';
Expand Down Expand Up @@ -171,13 +173,12 @@ const Activities: React.FC<ActivitiesProps> = ({}) => {
<div className=''>{getActivityDescription(activity)}</div>
{getExtendedDescription(activity)}
</div>
{isFollower(activity.actor.id) === false && (
<Button className='ml-auto' label='Follow' link onClick={(e) => {
e?.preventDefault();

alert('Implement me!');
}} />
)}
<FollowButton
className='ml-auto'
following={isFollower(activity.actor.id)}
handle={getUsername(activity.actor)}
type='link'
/>
</ActivityItem>
))}
</div>
Expand Down
Loading

0 comments on commit 776a328

Please sign in to comment.