use async_trait::async_trait;
use gitlab::AsyncGitlab;
use gitlab::api::{AsyncQuery, Endpoint};
use ironflow_core::error::OperationError;
use ironflow_core::operation::{Operation, OperationContext};
use serde_json::Value;
pub struct GitLabOp<E> {
client: AsyncGitlab,
endpoint: E,
}
impl<E> GitLabOp<E> {
pub(crate) fn new(client: AsyncGitlab, endpoint: E) -> Self {
Self { client, endpoint }
}
}
#[async_trait]
impl<E> Operation for GitLabOp<E>
where
E: Endpoint + Sync + Send,
{
fn kind(&self) -> &str {
"gitlab"
}
async fn execute(&self, _ctx: &OperationContext) -> Result<Value, OperationError> {
let result: Value =
self.endpoint
.query_async(&self.client)
.await
.map_err(|e| OperationError::Http {
status: None,
message: e.to_string(),
})?;
Ok(result)
}
fn input(&self) -> Option<Value> {
Some(Value::Object(serde_json::Map::from_iter([(
"endpoint".to_string(),
Value::String(self.endpoint.endpoint().into_owned()),
)])))
}
}