|
| 1 | +from selenium import webdriver |
| 2 | +from selenium.webdriver.common.by import By |
| 3 | +from selenium.webdriver.support.ui import WebDriverWait |
| 4 | +from selenium.webdriver.support import expected_conditions as EC |
| 5 | +import os |
| 6 | +import time |
| 7 | + |
| 8 | +GITLAB_URL="https://gitlab.example.com/" |
| 9 | +GITLAB_USER="user" |
| 10 | +GITLAB_PASSWORD="pa$$word" |
| 11 | +GITED_URL="https://gitea.example.com/" |
| 12 | +GITED_TOKEN="superSecret" |
| 13 | + |
| 14 | + |
| 15 | +driver = webdriver.Firefox(os.getcwd()+os.path.sep) |
| 16 | +driver.get(GITLAB_URL) |
| 17 | + |
| 18 | +# Gitlab login |
| 19 | +user = driver.find_element_by_id("user_login") |
| 20 | +user.send_keys(GITLAB_USER) |
| 21 | +pas = driver.find_element_by_id("user_password") |
| 22 | +pas.send_keys(GITLAB_PASSWORD) |
| 23 | +login = driver.find_element_by_name("commit").click() |
| 24 | + |
| 25 | +# Starting import process |
| 26 | +driver.get(GITLAB_URL+"/import/gitea/new") |
| 27 | +gitea_host = driver.find_element_by_name("gitea_host_url") |
| 28 | +gitea_host.send_keys(GITED_URL) |
| 29 | +gitea_token = driver.find_element_by_name("personal_access_token") |
| 30 | +gitea_token.send_keys(GITED_TOKEN) |
| 31 | +process = driver.find_element_by_name("commit").click() |
| 32 | + |
| 33 | +# iterate over table |
| 34 | +wait = WebDriverWait(driver, 10) |
| 35 | +table = wait.until(EC.presence_of_element_located((By.XPATH, '//table'))) |
| 36 | +for row in table.find_elements_by_xpath(".//tr"): |
| 37 | + group=row.get_attribute("data-qa-source-project").split("/")[0] |
| 38 | + # clicking select button to show dropdown menu and activate buttons |
| 39 | + row.find_element_by_class_name("gl-dropdown-toggle").click() |
| 40 | + time.sleep(1) |
| 41 | + # Finding project group |
| 42 | + for btn in row.find_elements_by_class_name("dropdown-item"): |
| 43 | + if btn.get_attribute("data-qa-group-name") == group: |
| 44 | + btn.click() |
| 45 | + time.sleep(1) |
| 46 | + # starting import |
| 47 | + import_button = row.find_element(By.XPATH, "//button[@data-qa-selector='import_button']") |
| 48 | + import_button.click() |
| 49 | + # Wait until import is ready |
| 50 | + while True: |
| 51 | + time.sleep(10) |
| 52 | + status = row.find_elements_by_class_name("gl-p-4")[-1].text |
| 53 | + if status == "Complete": |
| 54 | + break |
| 55 | + |
| 56 | +time.sleep(60) |
| 57 | + |
| 58 | +# closing session |
| 59 | +driver.quit() |
0 commit comments