3 2 2025-05-22 (C) Questetra, Inc. (MIT License) This item deletes a specified file from a repository on GitHub. この工程は、GitHub の指定したリポジトリのファイルを削除します。 https://support.questetra.com/bpmn-icons/service-task-github-file-delete/ https://support.questetra.com/ja/bpmn-icons/service-task-github-file-delete/ iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAABM9JREFUWEfF V2tQlFUYfs4ugiKgePkTiE3gCIssGWRhg1EwaE2OUZNjVDIFEwyJM12MSZKgokkNUdZNMhwCCg0p Bi8UxGVRblkgLHFJ12ZipImBLiAOg7h7mvfT/dz99lt2sR+8v3bPe3vOez0fw/+gqKgoF1LX6XQ3 79YMc1bxvuBgP2ZSRjHGH4SJqcCwGsCi2/pj4PgVCt7HOfuJK4y633p7B52x7RBAgCo0GCYeD4bn AKxyxiiAy+A4CQUrM/R1986kYxdAWFjYvH8nb6YoOE/igNpJx1ZiDNCbGCtcvMCloKOjY1rOhiyA ALXal93gb3PG0u7GsVSHca7hrmyfQa+/asOTHpBzTCMLQKIj5wqFAiaTyZGYmX8M85AlBWEVAQr7 +PUbufZu7uvrg+SkV3B/aAj8VqyAu7u7AGB09C8MXLqEH+oacKK8wi4gioTXQtc3LdNhBcBfFZrG OM+Xs7AjNRlpqSmgW89Evw8OIiExGUNDf8iKccZ2Xunr1piZIgCqdsZ5mbTgvL0Xo7ysFPeu9HM2 1EJU9uXm4VhRiY0OFSZnLN7cHXcABKpzwLBbqlH1zddQBQU67dxScGv8dlzs6rbV5fjIMKDPIIYA gIaMwqSsk/b5i/Hb8N677wgGJicnsSfrA6S9loKVfn7CLaempqBUKuHq6gqj0Sjkf8H8+Xgmboug MzY2hnWPRMkV6mWTwhhDw0oA4B+k3s6AYkuoi7y80N7cCBcXYdqCchuzabPwe/nyZRgZGRXFyanS RYmJieuIeGgdSoo+F3nfVlYhPSPTJgocSLjSry8RAASoQjTgbIelVPy2rcjOFKIk0MjoKNZviHaY Crr93pz3Rbmx8XGEPxxpq8f4YUNfT9otAIHqejA8bil1+GAuNsbGiEd0C7qNI6IuudDaBIqgmQJD 1sJolMwLjgbDgD76FoAgNU0oH0vjjbXVoL4nonyvXrPWkW+Rn5+3H09sjBX/U1u2trVL9YcM/Xpf Riv16vDf/wDwsJT45eIFuLm5CUdUYIEhDzgN4OOcbDwb97Qor9EWIF97RKo/YejXe9oF0Ha+AcuW LhWV1j8abVV4M6GpPHkca4JVoshb6btRdfqsPAB7Kag48SVC1SGiErUYtaEjWrLEGy26OrF7SD7y sVj8OTwsnwJ7RUgdQJ1gSY4KkSJGwH187hHV7KbPqghl2pBGcPv5RmH2U89T7xNRO3Z2diEjMxvU YkQ0sOK2bBbCLt0V39XUYufru2wDZ9mGcoOINPI+2YunntyE6elpYcq99MLzgiGacOERG0SjSS8n IH3XGzZOqHvCIyJx7dqEDc9qENkbxR4eC9FUXwMvT090detxvLwCqwL8cfpMNfr6B0SjFJ3Wpnob J3n5WnxacFSubKxH8e06kF1GVFS11aeEwUKjVt/TA925ZhQVl4qG6V3Q/XOblSPtkaM4qNHK16x0 GQkA7Kxj4lE9fFH4mbgVzzW3IPHVVNG4p6cHOn9sEf7Tgtp/4BCKS7+SdW53HZP0TA8S4lNbfpi9 B1WnzqKw6M7uooX1/ZlK1NTW4cAhje3YtYBi90FCMo6eZPLxdP7U4ZNMSMUsHqXOuxYkHT9KzQbn 9FluBjGnHyaWoZ2zTzNpfufs43SWhTZr8f8AaTovPzYDLOEAAAAASUVORK5CYII= { const auth = httpClient.createAuthSettingToken('Personal Access Token', 'github-token-12345'); configs.putObject('conf_Auth', auth); // 文字型データ項目を準備して、config に指定 const repositoryUrlDef = engine.createDataDefinition('リポジトリURL', 2, 'q_RepositoryUrl', 'STRING_TEXTFIELD'); configs.putObject('conf_RepositoryUrl', repositoryUrlDef); // 文字型データ項目の値(リポジトリURL)を指定 engine.setData(repositoryUrlDef, repositoryUrl); configs.put('conf_Path', path); // 文字型データ項目を準備して、config に指定 const branchDef = engine.createDataDefinition('ブランチ', 3, 'q_Branch', 'STRING_TEXTFIELD'); configs.putObject('conf_Branch', branchDef); // 文字型データ項目の値(ブランチ)を指定 engine.setData(branchDef, branch); // 文字型データ項目を準備して、config に指定 const fileShaDef = engine.createDataDefinition('ファイルSHA', 4, 'q_SHA', 'STRING_TEXTFIELD'); configs.putObject('conf_Hash', fileShaDef); // 文字型データ項目の値(SHA)を指定 engine.setData(fileShaDef, hash); configs.put('conf_Message', message); }; /** * 異常系のテスト * @param errorMsg */ const assertError = (errorMsg) => { let failed = false; try { main(); } catch (e) { failed = true; expect(e.message).toEqual(errorMsg); } if (!failed) { fail('No error was thrown.'); } }; /** * conf_RepositoryUrl にデータ項目を設定しているが、そのデータ項目の値が空でエラーになる場合 */ test("Repository's URL is blank - Repository's URL specified by String Data", () => { prepareConfigs(null, 'path0/test.txt', 'branchQ0', 'hash-0000-012345678901234567890123456789', 'delete a file'); assertError("Repository's URL is blank."); }); /** * リポジトリURLが不正 */ test("Invalid repository URL - handle specified by String Data", () => { prepareConfigs("https://invalid.com/user1Org/user1Org123", 'path1/test.txt', 'branchQ1', 'hash-0001-012345678901234567890123456789', 'delete a file'); assertError("Invalid repository URL."); }); /** * ファイルパスが空 */ test('File Path is blank', () => { prepareConfigs("https://github.com/user1Org/user1Org123", '', 'branchQ2', 'hash-0002-012345678901234567890123456789', 'delete a file'); assertError('File Path is blank.'); }); /** * SHA が空 */ test('SHA of the file is blank', () => { prepareConfigs("https://github.com/user1Org/user1Org123", 'path1/test.txt', 'branchQ2', null, 'delete a file'); assertError('SHA of the file is blank.'); }); /** * コミットメッセージが空 */ test('Message is blank', () => { prepareConfigs("https://github.com/user1Org/user1Org123", 'path1/test.txt', 'branchQ2', 'hash-0002-012345678901234567890123456789', ''); assertError('Commit Message is blank.'); }); /** * リクエストのテスト(ファイルを削除する) * @param {Object} request * @param request.url * @param request.method * @param ownerAndRepo * @param path * @param branch * @param hash * @param message */ const assertDeleteRequest = ({ url, method }, ownerAndRepo, path, branch, hash, message) => { if(branch === null || branch === ''){ expect(url).toEqual(`https://api.github.com/repos/${ownerAndRepo}/contents/${path}?sha=${hash}&message=${message}`); } else { expect(url).toEqual(`https://api.github.com/repos/${ownerAndRepo}/contents/${path}?sha=${hash}&message=${message}&branch=${branch}`); } expect(method).toEqual('DELETE'); }; /** * ファイルを削除する API リクエストでエラー */ test('delete Failed', () => { prepareConfigs("https://github.com/user1Org/user1Org123", 'test3.txt', 'branchQ3', 'hash-0003-012345678901234567890123456789', 'delete'); httpClient.setRequestHandler((request) => { assertDeleteRequest(request, 'user1Org/user1Org123', 'test3.txt', 'branchQ3', 'hash-0003-012345678901234567890123456789', 'delete'); return httpClient.createHttpResponse(404, 'application/json', '{}'); }); assertError('Failed to delete a file. status: 404'); }); /** * 削除成功 * URL と ブランチをデータ項目で指定 */ test('Succeed - delete', () => { prepareConfigs("https://github.com/user1Org/user1Org123", 'test3.txt', 'branchQ3', 'hash-0003-012345678901234567890123456789', 'delete_test1'); httpClient.setRequestHandler((request) => { assertDeleteRequest(request, 'user1Org/user1Org123', 'test3.txt', 'branchQ3', 'hash-0003-012345678901234567890123456789', 'delete_test1'); return httpClient.createHttpResponse(200, 'application/json', '{}'); }); main(); }); /** * 削除成功 * ブランチ無 * データ項目を指定し、その値が空(null)の場合 */ test('Succeed - delete - no-branch', () => { prepareConfigs("https://github.com/user1/user1repo", 'path1/test.png', null, 'hash-0000-012345678901234567890123456789', 'delete'); httpClient.setRequestHandler((request) => { assertDeleteRequest(request, 'user1/user1repo', 'path1/test.png', null, 'hash-0000-012345678901234567890123456789', 'delete'); return httpClient.createHttpResponse(200, 'application/json', '{}'); }); main(); }); /** * 削除成功 * ブランチ無 * 未指定(固定値を選択し、指定なし)の場合 */ test('Succeed - delete - no-branch - branch is fixed value', () => { prepareConfigs("https://github.com/user1/user1repo", 'path1/test.png', '', 'hash-0000-012345678901234567890123456789', 'deleteFile'); //URL と ブランチを固定値で指定 configs.put('conf_Branch', ''); httpClient.setRequestHandler((request) => { assertDeleteRequest(request, 'user1/user1repo', 'path1/test.png', '', 'hash-0000-012345678901234567890123456789', 'deleteFile'); return httpClient.createHttpResponse(200, 'application/json', '{}'); }); main(); }); /** * 削除成功 * URL と ブランチを固定値で指定 */ test('Succeed - url and branch are fixed value ', () => { prepareConfigs('', 'path2/test.pdf', '', 'hash-0001-012345678901234567890123456789', 'delete'); //URL と ブランチを固定値で指定 configs.put('conf_RepositoryUrl', 'https://github.com/user2/user2repo'); configs.put('conf_Branch', 'branchQ'); httpClient.setRequestHandler((request) => { assertDeleteRequest(request, 'user2/user2repo', 'path2/test.pdf', 'branchQ', 'hash-0001-012345678901234567890123456789', 'delete'); return httpClient.createHttpResponse(200, 'application/json', '{}'); }); main(); }); ]]>