Add optional screenshots to bug reports

This commit is contained in:
2026-09-15 21:16:06 +02:00
parent 39af9ecdb4
commit 5d3ae10036
10 changed files with 263 additions and 12 deletions
+39
View File
@@ -29,6 +29,45 @@ class GiteaTests(unittest.TestCase):
self.assertEqual(requests[-1].url.path, '/api/v1/repos/kai/pingu-concerts/issues')
self.assertNotIn('test-secret', str(requests[-1].url))
def test_screenshot_is_uploaded_as_issue_asset_and_linked_into_issue_body(self):
requests = []
image = b"sanitized-raster-image-bytes"
def handler(request):
requests.append(request)
if request.url.path.endswith('/user'):
return httpx.Response(200, json={'login':'metalcircle-bot'})
if request.url.path.endswith('/labels'):
return httpx.Response(200, json=[])
if request.method == 'POST' and request.url.path.endswith('/issues'):
return httpx.Response(201, json={'number':123,'user':{'login':'metalcircle-bot'}})
if request.method == 'POST' and request.url.path.endswith('/issues/123/assets'):
self.assertEqual(request.url.params['name'], 'screenshot-safe.png')
self.assertIn('multipart/form-data', request.headers['content-type'])
self.assertIn(image, request.read())
self.assertIn('filename="screenshot-safe.png"', request.read().decode('latin1'))
return httpx.Response(201, json={'browser_download_url':'http://gitea.invalid/attachments/safe-id','id':5})
if request.method == 'PATCH' and request.url.path.endswith('/issues/123'):
self.assertIn('![Bug report screenshot](<http://gitea.invalid/attachments/safe-id>)', json.loads(request.content)['body'])
return httpx.Response(200, json={'number':123})
raise AssertionError(f'unexpected request {request.method} {request.url.path}')
result=self.service(handler).create_issue('Screenshot test','safe body','android',
screenshot=('screenshot-safe.png',image,'image/png'))
self.assertEqual(result,123)
self.assertEqual([request.method for request in requests],['GET','GET','POST','POST','PATCH'])
self.assertNotIn(b'test-secret-never-print', b''.join(request.content for request in requests))
def test_screenshot_upload_failure_is_uncertain_and_secret_free(self):
def handler(request):
if request.url.path.endswith('/user'): return httpx.Response(200,json={'login':'metalcircle-bot'})
if request.url.path.endswith('/labels'): return httpx.Response(200,json=[])
if request.method == 'POST' and request.url.path.endswith('/issues'): return httpx.Response(201,json={'number':9,'user':{'login':'metalcircle-bot'}})
return httpx.Response(413,text='private upload failure details')
with self.assertLogs('gitea_service','WARNING') as logs:
with self.assertRaises(GiteaError) as caught:
self.service(handler).create_issue('Title','Body','general',screenshot=('screenshot.jpg',b'image','image/jpeg'))
self.assertTrue(caught.exception.uncertain)
self.assertNotIn('private upload failure details','\n'.join(logs.output))
def test_missing_or_inaccessible_labels_do_not_block(self):
for response in (httpx.Response(200, json=[]), httpx.Response(403), httpx.Response(200, json={'invalid': True})):
def handler(request):