Skip to content

Commit 76a255c

Browse files
committed
updated with some indentation fix in docker-compose + contributermd file and brought changes done in the old pr by matej
1 parent ea9782e commit 76a255c

11 files changed

Lines changed: 202 additions & 21 deletions

File tree

.github/workflows/tests-external.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ permissions:
99

1010
jobs:
1111
tests:
12-
name: Tests (External)
12+
name: ${{ matrix.adapter }}
1313
runs-on: ubuntu-latest
1414

1515
if: github.event.label.name == 'test'
1616

17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
adapter: [gitea, forgejo, github, gitlab, gogs]
21+
1722
steps:
1823
- name: Check out the repo
1924
uses: actions/checkout@v4
@@ -26,15 +31,15 @@ jobs:
2631
TESTS_GITHUB_APP_IDENTIFIER: ${{ secrets.TESTS_GITHUB_APP_IDENTIFIER }}
2732
TESTS_GITHUB_INSTALLATION_ID: ${{ secrets.TESTS_GITHUB_INSTALLATION_ID }}
2833
run: |
29-
docker compose up -d
34+
docker compose --profile ${{ matrix.adapter }} up -d
3035
sleep 15
3136
3237
- name: Doctor
3338
run: |
34-
docker compose logs
39+
docker compose --profile ${{ matrix.adapter }} logs
3540
docker ps
3641
docker network ls
3742
3843
- name: Run Tests
3944
run: |
40-
docker compose exec -T tests vendor/bin/phpunit --configuration phpunit.xml tests
45+
docker compose exec -T tests vendor/bin/phpunit --configuration phpunit.xml --testsuite ${{ matrix.adapter }}

.github/workflows/tests.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ permissions:
88

99
jobs:
1010
tests:
11-
name: Tests
11+
name: ${{ matrix.adapter }}
1212
runs-on: ubuntu-latest
1313
if: github.event.pull_request.head.repo.full_name == github.repository
1414

15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
adapter: [gitea, forgejo, github, gitlab, gogs]
19+
1520
steps:
1621
- name: Check out the repo
1722
uses: actions/checkout@v4
@@ -22,15 +27,15 @@ jobs:
2227
TESTS_GITHUB_APP_IDENTIFIER: ${{ secrets.TESTS_GITHUB_APP_IDENTIFIER }}
2328
TESTS_GITHUB_INSTALLATION_ID: ${{ secrets.TESTS_GITHUB_INSTALLATION_ID }}
2429
run: |
25-
docker compose up -d
30+
docker compose --profile ${{ matrix.adapter }} up -d
2631
sleep 15
2732
2833
- name: Doctor
2934
run: |
30-
docker compose logs
35+
docker compose --profile ${{ matrix.adapter }} logs
3136
docker ps
3237
docker network ls
3338
3439
- name: Run Tests
3540
run: |
36-
docker compose exec -T tests vendor/bin/phpunit --configuration phpunit.xml tests
41+
docker compose exec -T tests vendor/bin/phpunit --configuration phpunit.xml --testsuite ${{ matrix.adapter }}

CONTRIBUTING.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,30 @@ This will allow the Utopia-php community to have sufficient discussion about the
7676

7777
This is also important for the Utopia-php lead developers to be able to give technical input and different emphasis regarding the feature design and architecture. Some bigger features might need to go through our [RFC process](https://github.com/appwrite/rfc).
7878

79+
## Running Tests
80+
81+
Tests are split by adapter. Each adapter has its own Docker Compose profile and PHPUnit test suite.
82+
83+
To start the stack and run tests for a specific adapter:
84+
85+
```bash
86+
docker compose --profile <adapter> up -d
87+
sleep 15
88+
docker compose exec -T tests vendor/bin/phpunit --configuration phpunit.xml --testsuite <adapter>
89+
```
90+
91+
Where `<adapter>` is one of: `gitea`, `forgejo`, `github`, `gitlab`, `gogs`.
92+
93+
For example, to run Gitea tests:
94+
95+
```bash
96+
docker compose --profile gitea up -d
97+
sleep 15
98+
docker compose exec -T tests vendor/bin/phpunit --configuration phpunit.xml --testsuite gitea
99+
```
100+
101+
The `github` adapter does not require any local services — only the GitHub secrets (`TESTS_GITHUB_PRIVATE_KEY`, `TESTS_GITHUB_APP_IDENTIFIER`, `TESTS_GITHUB_INSTALLATION_ID`) as environment variables.
102+
79103
## Adding A New Adapter
80104

81105
You can follow our [Adding new VCS Adapter](docs/add-new-vcs-adapter.md) tutorial to add a new VCS adapter like GitLab, Bitbucket etc. in this library.

docker-compose.yml

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,32 @@ services:
2121
- TESTS_GITLAB_URL=http://gitlab:80
2222
depends_on:
2323
gitea:
24-
condition: service_healthy
24+
condition: service_started
25+
required: false
2526
gitea-bootstrap:
2627
condition: service_completed_successfully
28+
required: false
2729
forgejo:
28-
condition: service_healthy
30+
condition: service_started
31+
required: false
2932
forgejo-bootstrap:
3033
condition: service_completed_successfully
34+
required: false
3135
gogs:
32-
condition: service_healthy
36+
condition: service_started
37+
required: false
3338
gogs-bootstrap:
3439
condition: service_completed_successfully
40+
required: false
3541
gitlab:
36-
condition: service_healthy
42+
condition: service_started
43+
required: false
3744
gitlab-bootstrap:
3845
condition: service_completed_successfully
46+
required: false
3947
request-catcher:
4048
condition: service_started
49+
required: false
4150

4251
gitea:
4352
image: gitea/gitea:1.21.5
@@ -46,7 +55,7 @@ services:
4655
- USER_GID=1000
4756
- GITEA__database__DB_TYPE=sqlite3
4857
- GITEA__security__INSTALL_LOCK=true
49-
- GITEA__webhook__ALLOWED_HOST_LIST=*
58+
- GITEA__webhook__ALLOWED_HOST_LIST=*
5059
- GITEA__webhook__SKIP_TLS_VERIFY=true
5160
- GITEA__webhook__DELIVER_TIMEOUT=10
5261
- GITEA__server__LOCAL_ROOT_URL=http://gitea:3000/
@@ -60,6 +69,8 @@ services:
6069
timeout: 5s
6170
retries: 10
6271
start_period: 10s
72+
profiles:
73+
- gitea
6374

6475
gitea-bootstrap:
6576
image: gitea/gitea:1.21.5
@@ -68,6 +79,7 @@ services:
6879
depends_on:
6980
gitea:
7081
condition: service_healthy
82+
required: false
7183
entrypoint: /bin/sh
7284
environment:
7385
- GITEA_ADMIN_USERNAME=${GITEA_ADMIN_USERNAME:-utopia}
@@ -81,10 +93,16 @@ services:
8193
echo $$TOKEN > /data/gitea/token.txt;
8294
fi
8395
"
96+
profiles:
97+
- gitea
8498
request-catcher:
8599
image: appwrite/requestcatcher:1.1.0
86100
ports:
87101
- "5000:5000"
102+
profiles:
103+
- gitea
104+
- forgejo
105+
- gogs
88106

89107
forgejo:
90108
image: codeberg.org/forgejo/forgejo:9
@@ -105,6 +123,8 @@ services:
105123
timeout: 5s
106124
retries: 10
107125
start_period: 10s
126+
profiles:
127+
- forgejo
108128

109129
forgejo-bootstrap:
110130
image: codeberg.org/forgejo/forgejo:9
@@ -113,6 +133,7 @@ services:
113133
depends_on:
114134
forgejo:
115135
condition: service_healthy
136+
required: false
116137
entrypoint: /bin/sh
117138
environment:
118139
- FORGEJO_ADMIN_USERNAME=${FORGEJO_ADMIN_USERNAME:-utopia}
@@ -126,6 +147,8 @@ services:
126147
echo $$TOKEN > /data/gitea/token.txt;
127148
fi
128149
"
150+
profiles:
151+
- forgejo
129152

130153
gogs:
131154
image: gogs/gogs:0.14
@@ -140,6 +163,8 @@ services:
140163
timeout: 5s
141164
retries: 10
142165
start_period: 15s
166+
profiles:
167+
- gogs
143168

144169
gogs-bootstrap:
145170
image: gogs/gogs:0.14
@@ -149,6 +174,7 @@ services:
149174
depends_on:
150175
gogs:
151176
condition: service_healthy
177+
required: false
152178
entrypoint: /bin/sh
153179
environment:
154180
- GOGS_ADMIN_USERNAME=${GOGS_ADMIN_USERNAME:-utopia}
@@ -177,6 +203,8 @@ services:
177203
mkdir -p /data/gogs
178204
echo $$TOKEN > /data/gogs/token.txt
179205
fi
206+
profiles:
207+
- gogs
180208

181209
gitlab:
182210
image: gitlab/gitlab-ce:18.10.1-ce.0
@@ -194,6 +222,8 @@ services:
194222
timeout: 10s
195223
retries: 20
196224
start_period: 300s
225+
profiles:
226+
- gitlab
197227

198228
gitlab-bootstrap:
199229
image: alpine/curl:8.12.1
@@ -248,6 +278,8 @@ services:
248278
-H "Content-Type: application/json" \
249279
-d '{"allow_local_requests_from_web_hooks_and_services":true,"allow_local_requests_from_system_hooks":true}'
250280
echo "Local webhook requests enabled"
281+
profiles:
282+
- gitlab
251283

252284
volumes:
253285
gitea-data:

phpunit.xml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,20 @@
99
stopOnFailure="false"
1010
>
1111
<testsuites>
12-
<testsuite name="Application Test Suite">
13-
<directory>./tests/</directory>
12+
<testsuite name="gitea">
13+
<file>./tests/VCS/Adapter/GiteaTest.php</file>
14+
</testsuite>
15+
<testsuite name="forgejo">
16+
<file>./tests/VCS/Adapter/ForgejoTest.php</file>
17+
</testsuite>
18+
<testsuite name="github">
19+
<file>./tests/VCS/Adapter/GitHubTest.php</file>
20+
</testsuite>
21+
<testsuite name="gitlab">
22+
<file>./tests/VCS/Adapter/GitLabTest.php</file>
23+
</testsuite>
24+
<testsuite name="gogs">
25+
<file>./tests/VCS/Adapter/GogsTest.php</file>
1426
</testsuite>
1527
</testsuites>
1628
</phpunit>

src/VCS/Adapter/Git/Gitea.php

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,14 @@ public function createRepository(string $owner, string $repositoryName, bool $pr
100100
'private' => $private,
101101
]);
102102

103-
return $response['body'] ?? [];
104-
// return is_array($body) ? $body : [];
103+
$result = $response['body'] ?? [];
104+
if (is_array($result)) {
105+
// Gitea's API does not expose `pushed_at`; surface `updated_at` under that key
106+
// for parity with the other VCS adapters (GitHub, GitLab).
107+
$result['pushed_at'] = $result['pushed_at'] ?? ($result['updated_at'] ?? '');
108+
}
109+
return is_array($result) ? $result : [];
110+
;
105111
}
106112

107113
public function createOrganization(string $orgName): string
@@ -207,6 +213,13 @@ public function searchRepositories(string $owner, int $page, int $per_page, stri
207213
$offset = ($page - 1) * $per_page;
208214
$pagedRepos = array_slice($filteredRepos, $offset, $per_page);
209215

216+
foreach ($pagedRepos as &$repo) {
217+
if (is_array($repo)) {
218+
$repo['pushed_at'] = $repo['pushed_at'] ?? ($repo['updated_at'] ?? '');
219+
}
220+
}
221+
unset($repo);
222+
210223
return [
211224
'items' => $pagedRepos,
212225
'total' => $total,
@@ -241,7 +254,11 @@ public function getRepository(string $owner, string $repositoryName): array
241254
throw new RepositoryNotFound("Repository not found");
242255
}
243256

244-
return $response['body'] ?? [];
257+
$result = $response['body'] ?? [];
258+
if (is_array($result)) {
259+
$result['pushed_at'] = $result['pushed_at'] ?? ($result['updated_at'] ?? '');
260+
}
261+
return is_array($result) ? $result : [];
245262
}
246263

247264
public function getRepositoryName(string $repositoryId): string
@@ -724,7 +741,7 @@ public function listBranches(string $owner, string $repositoryName): array
724741
for ($currentPage = 1; $currentPage <= $maxPages; $currentPage++) {
725742
$url = "/repos/{$owner}/{$repositoryName}/branches?page={$currentPage}&limit={$perPage}";
726743

727-
$response = $this->call(self::METHOD_GET, $url, ['Authorization' => "token $this->accessToken"]);
744+
$response = $this->call(self::METHOD_GET, $url, ['Authorization' => "token $this->accessToken"], decode: false);
728745

729746
$responseHeaders = $response['headers'] ?? [];
730747
$responseHeadersStatusCode = $responseHeaders['status-code'] ?? 0;
@@ -740,7 +757,7 @@ public function listBranches(string $owner, string $repositoryName): array
740757
break;
741758
}
742759

743-
$responseBody = $response['body'] ?? [];
760+
$responseBody = \json_decode($response['body'] ?? '', true);
744761

745762
if (!is_array($responseBody)) {
746763
break;
@@ -896,6 +913,9 @@ public function updateCommitStatus(string $repositoryName, string $commitHash, s
896913
*/
897914
public function generateCloneCommand(string $owner, string $repositoryName, string $version, string $versionType, string $directory, string $rootDirectory): string
898915
{
916+
if (empty($rootDirectory)) {
917+
$rootDirectory = '*';
918+
}
899919
$cloneUrl = "{$this->giteaUrl}/{$owner}/{$repositoryName}";
900920
if (!empty($this->accessToken)) {
901921
$cloneUrl = str_replace('://', "://{$owner}:{$this->accessToken}@", $this->giteaUrl) . "/{$owner}/{$repositoryName}";

src/VCS/Adapter/Git/Gogs.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ public function createRepository(string $owner, string $repositoryName, bool $pr
4040
'readme' => 'Default',
4141
]);
4242

43-
return $response['body'] ?? [];
43+
$result = $response['body'] ?? [];
44+
if (is_array($result)) {
45+
// Gogs' API does not expose `pushed_at`; surface `updated_at` under that key
46+
// for parity with the other VCS adapters (GitHub, GitLab).
47+
$result['pushed_at'] = $result['pushed_at'] ?? ($result['updated_at'] ?? '');
48+
}
49+
return is_array($result) ? $result : [];
4450
}
4551

4652
/**
@@ -88,6 +94,15 @@ public function searchRepositories(string $owner, int $page, int $per_page, stri
8894
$offset = ($page - 1) * $per_page;
8995
$pagedRepos = array_slice($responseBody, $offset, $per_page);
9096

97+
// Gogs' API does not expose `pushed_at`; surface `updated_at` under that key
98+
// for parity with the other VCS adapters (GitHub, GitLab).
99+
foreach ($pagedRepos as &$repo) {
100+
if (is_array($repo)) {
101+
$repo['pushed_at'] = $repo['pushed_at'] ?? ($repo['updated_at'] ?? '');
102+
}
103+
}
104+
unset($repo);
105+
91106
return [
92107
'items' => $pagedRepos,
93108
'total' => $total,

0 commit comments

Comments
 (0)