Skip to content

Commit 2b81213

Browse files
authored
Merge pull request #105 from jaysomani/fix/pushed-at-normalization
initial normalization for pushed_at
2 parents db749a6 + 763eb92 commit 2b81213

13 files changed

Lines changed: 207 additions & 23 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: 38 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,17 @@ 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
106+
- gitlab
88107

89108
forgejo:
90109
image: codeberg.org/forgejo/forgejo:9
@@ -105,6 +124,8 @@ services:
105124
timeout: 5s
106125
retries: 10
107126
start_period: 10s
127+
profiles:
128+
- forgejo
108129

109130
forgejo-bootstrap:
110131
image: codeberg.org/forgejo/forgejo:9
@@ -113,6 +134,7 @@ services:
113134
depends_on:
114135
forgejo:
115136
condition: service_healthy
137+
required: false
116138
entrypoint: /bin/sh
117139
environment:
118140
- FORGEJO_ADMIN_USERNAME=${FORGEJO_ADMIN_USERNAME:-utopia}
@@ -126,6 +148,8 @@ services:
126148
echo $$TOKEN > /data/gitea/token.txt;
127149
fi
128150
"
151+
profiles:
152+
- forgejo
129153

130154
gogs:
131155
image: gogs/gogs:0.14
@@ -140,6 +164,8 @@ services:
140164
timeout: 5s
141165
retries: 10
142166
start_period: 15s
167+
profiles:
168+
- gogs
143169

144170
gogs-bootstrap:
145171
image: gogs/gogs:0.14
@@ -149,6 +175,7 @@ services:
149175
depends_on:
150176
gogs:
151177
condition: service_healthy
178+
required: false
152179
entrypoint: /bin/sh
153180
environment:
154181
- GOGS_ADMIN_USERNAME=${GOGS_ADMIN_USERNAME:-utopia}
@@ -177,6 +204,8 @@ services:
177204
mkdir -p /data/gogs
178205
echo $$TOKEN > /data/gogs/token.txt
179206
fi
207+
profiles:
208+
- gogs
180209

181210
gitlab:
182211
image: gitlab/gitlab-ce:18.10.1-ce.0
@@ -194,6 +223,8 @@ services:
194223
timeout: 10s
195224
retries: 20
196225
start_period: 300s
226+
profiles:
227+
- gitlab
197228

198229
gitlab-bootstrap:
199230
image: alpine/curl:8.12.1
@@ -248,6 +279,8 @@ services:
248279
-H "Content-Type: application/json" \
249280
-d '{"allow_local_requests_from_web_hooks_and_services":true,"allow_local_requests_from_system_hooks":true}'
250281
echo "Local webhook requests enabled"
282+
profiles:
283+
- gitlab
251284

252285
volumes:
253286
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/GitLab.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ public function createRepository(string $owner, string $repositoryName, bool $pr
118118
if ($statusCode >= 400) {
119119
throw new Exception("Creating repository {$repositoryName} failed with status code {$statusCode}");
120120
}
121-
return is_array($body) ? $body : [];
121+
$result = is_array($body) ? $body : [];
122+
$result['pushed_at'] = $result['last_activity_at'] ?? '';
123+
return $result;
122124
}
123125

124126
public function deleteRepository(string $owner, string $repositoryName): bool
@@ -152,7 +154,11 @@ public function getRepository(string $owner, string $repositoryName): array
152154
throw new RepositoryNotFound("Repository not found");
153155
}
154156

155-
return $response['body'] ?? [];
157+
$result = $response['body'] ?? [];
158+
if (is_array($result)) {
159+
$result['pushed_at'] = $result['last_activity_at'] ?? '';
160+
}
161+
return is_array($result) ? $result : [];
156162
}
157163

158164

@@ -207,6 +213,7 @@ public function searchRepositories(string $owner, int $page, int $per_page, stri
207213
'name' => $repo['name'] ?? '',
208214
'description' => $repo['description'] ?? '',
209215
'private' => ($repo['visibility'] ?? '') === 'private',
216+
'pushed_at' => $repo['last_activity_at'] ?? '',
210217
];
211218
}
212219

src/VCS/Adapter/Git/Gitea.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,13 @@ 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 : [];
105110
}
106111

107112
public function createOrganization(string $orgName): string
@@ -207,6 +212,13 @@ public function searchRepositories(string $owner, int $page, int $per_page, stri
207212
$offset = ($page - 1) * $per_page;
208213
$pagedRepos = array_slice($filteredRepos, $offset, $per_page);
209214

215+
foreach ($pagedRepos as &$repo) {
216+
if (is_array($repo)) {
217+
$repo['pushed_at'] = $repo['pushed_at'] ?? ($repo['updated_at'] ?? '');
218+
}
219+
}
220+
unset($repo);
221+
210222
return [
211223
'items' => $pagedRepos,
212224
'total' => $total,
@@ -241,7 +253,11 @@ public function getRepository(string $owner, string $repositoryName): array
241253
throw new RepositoryNotFound("Repository not found");
242254
}
243255

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

247263
public function getRepositoryName(string $repositoryId): string
@@ -724,7 +740,7 @@ public function listBranches(string $owner, string $repositoryName): array
724740
for ($currentPage = 1; $currentPage <= $maxPages; $currentPage++) {
725741
$url = "/repos/{$owner}/{$repositoryName}/branches?page={$currentPage}&limit={$perPage}";
726742

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

729745
$responseHeaders = $response['headers'] ?? [];
730746
$responseHeadersStatusCode = $responseHeaders['status-code'] ?? 0;
@@ -740,7 +756,7 @@ public function listBranches(string $owner, string $repositoryName): array
740756
break;
741757
}
742758

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

745761
if (!is_array($responseBody)) {
746762
break;
@@ -896,6 +912,9 @@ public function updateCommitStatus(string $repositoryName, string $commitHash, s
896912
*/
897913
public function generateCloneCommand(string $owner, string $repositoryName, string $version, string $versionType, string $directory, string $rootDirectory): string
898914
{
915+
if (empty($rootDirectory)) {
916+
$rootDirectory = '*';
917+
}
899918
$cloneUrl = "{$this->giteaUrl}/{$owner}/{$repositoryName}";
900919
if (!empty($this->accessToken)) {
901920
$cloneUrl = str_replace('://', "://{$owner}:{$this->accessToken}@", $this->giteaUrl) . "/{$owner}/{$repositoryName}";

0 commit comments

Comments
 (0)