This Python script allows you to import GitLab projects from a CSV file using the GitLab API.
- Python 3.x
requests
librarycsv
library- GitLab private token
- Configure the parsing of command line arguments by providing a private token for GitLab API and the path to the CSV file:
parser.add_argument('--token', required=True, help='Private token for GitLab API.')
parser.add_argument('--csv', required=True, help='Path to the CSV file.')
- (Optional) Configure proxy settings if needed:
# Proxy Settings
os.environ['http_proxy'] = "http://PROXY_HOST:PROXY_PORT"
os.environ['https_proxy'] = "https://PROXY_HOST:PROXY_PORT"
- Set up logging to record the import results:
# Logging Settings
logging.basicConfig(filename='import_result.log', level=logging.INFO, format='%(asctime)s - %(message)s', datefmt='%Y/%m/%d %H:%M:%S')
- Run the script by providing the required arguments:
python import_gitlab.py --token YOUR_PRIVATE_TOKEN --csv PATH_TO_CSV_FILE
The CSV file should contain the following columns in each row:
- File path of the project export file
- Namespace for the project
- Path for the project
The script does the following steps:
- Opens the CSV file and reads each row.
- Loads the project export file.
- Sends a request to the GitLab API endpoint to upload the export data.
- Checks the response and logs success or error messages.
- Waits 12 seconds between requests to avoid hitting API call limits.
The script generates a import_result.log
file to log the status of each import attempt, including success and error messages with timestamps.
This project is licensed under the MIT License - see the LICENSE file for details.
Note: This script is designed to work with GitLab API, ensure you have a valid token and correct CSV file format.